報錯是(error during evaluation),見下圖。
代碼大概是下面這樣,
import store from './store.js'
computed: {
...mapGetters('project', [
'isOpenSupplyNeed',
]),
a(){
return store.getters['project/isOpenSupplyNeed']
}
},
然後就是在vue-devtools
面板裏看到這樣的報錯
然而另一個屬性a,是有正確的值的。
後來下斷點看報錯,發現了問題。
this.$store是undefined。
因爲在new Vue的時候,沒有將store注入進來,導致vuex裏的代碼this.$store獲取不到。
結論就是如果用到這些輔助函數,一定要保證new Vue的時候注入store。