2 回答

TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個(gè)贊
問(wèn)題出在computed物業(yè)上。它應(yīng)該是:
computed: {
books () {
return this.$store.getters.books;
}
}
為方便起見(jiàn),您可以使用vuex mapGetters:
import { mapGetters } from 'vuex'
export default {
//..
computed: {
...mapGetters(['books'])
}
}

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
為此,您需要觀看
請(qǐng)注意這個(gè)例子:
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)
}
}
現(xiàn)在你可以重新渲染你的組件
<template>
<div :key="parentKey">{{books}}</div>
</template>
data() {
return {
parentKey: 'first'
}
}
只是你需要parentKey在手表上改變
watch: {
books(newVal, oldVal) {
this.parentKey = Math.random()
}
}
添加回答
舉報(bào)