Vue-stash 反应性在数据变量中不起作用
Vue-stash reactivity not working in data variables
我正在使用 Vue-stash 作为 vuex 的替代品。 Vue-stash 本身是反应式的。但是,如果我在数据变量中使用它,该变量不会改变
<template>
<div>
{{id}} // not reactive
</div>
</template>
<script>
export default {
data() {
return {
id: this.$store.id
}
}
}
</script>
Vue 实例的数据属性 仅在实例化时设置一次。
如果您希望 id
始终反映 this.$store.id
的值,您应该使用计算 属性:
export default {
computed: {
id() {
return this.$store.id;
}
}
}
我正在使用 Vue-stash 作为 vuex 的替代品。 Vue-stash 本身是反应式的。但是,如果我在数据变量中使用它,该变量不会改变
<template>
<div>
{{id}} // not reactive
</div>
</template>
<script>
export default {
data() {
return {
id: this.$store.id
}
}
}
</script>
Vue 实例的数据属性 仅在实例化时设置一次。
如果您希望 id
始终反映 this.$store.id
的值,您应该使用计算 属性:
export default {
computed: {
id() {
return this.$store.id;
}
}
}