2 回答
TA貢獻1886條經驗 獲得超2個贊
問題出在computed物業上。它應該是:
computed: {
books () {
return this.$store.getters.books;
}
}
為方便起見,您可以使用vuex mapGetters:
import { mapGetters } from 'vuex'
export default {
//..
computed: {
...mapGetters(['books'])
}
}
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()
}
}
添加回答
舉報
