2 回答
![?](http://img1.sycdn.imooc.com/545869470001a00302200220-100-100.jpg)
TA贡献1886条经验 获得超2个赞
问题出在computed物业上。它应该是:
computed: {
books () {
return this.$store.getters.books;
}
}
为方便起见,您可以使用vuex mapGetters:
import { mapGetters } from 'vuex'
export default {
//..
computed: {
...mapGetters(['books'])
}
}
![?](http://img1.sycdn.imooc.com/545847aa0001063202200220-100-100.jpg)
TA贡献1828条经验 获得超13个赞
为此,您需要观看
请注意这个例子:
methods: {
...
},
computed: {
books () {
return this.$store.getters.books;
}
},
watch: {
books(newVal, oldVal) {
console.log('change books value and this new value is:' + newVal + ' and old value is ' + oldVal)
}
}
现在你可以重新渲染你的组件
<template>
<div :key="parentKey">{{books}}</div>
</template>
data() {
return {
parentKey: 'first'
}
}
只是你需要parentKey在手表上改变
watch: {
books(newVal, oldVal) {
this.parentKey = Math.random()
}
}
添加回答
举报