【发布时间】:2021-05-16 13:47:41
【问题描述】:
我在 vuex 存储中有一个对象,其中包含一些我需要在组件中使用的数据,我已经使用组件中的 getter 访问了数据。我正在尝试将该对象的初始值保存在一个变量中,当存储中的数据发生更改时它不会更改/更新,这将允许我进行比较条件。
代码如下,'getSelectedLocation'访问的对象就是我需要保留的原始值。
data() {
return {
toggle: this.getSelectedLocation?.local,
}
},
computed: {
...mapGetters({ getUser: 'user/getUser', getSelectedLocation: 'support/getSelectedLocation' }),
},
methods: {
async updateUsersLocation() {
const usersCol = new UsersCollection(this.$fire.firestore)
const id = this.getUser.id
const location = this.getSelectedLocation
return await usersCol.updateUsersLocation({ id, location })
},
},
}
【问题讨论】:
-
我认为@Igor Moraru 向您展示的答案会奏效。为了清楚起见,您想保存在函数变量或组件变量中(在您的数据中)?
标签: javascript vue.js state nuxt.js vuex