我有一個組件,我想在其中顯示狀態中定義的資料。我已經創建了吸氣劑:
export default createStore({
state: {
foo: true,
},
getters: {
getFoo: state => state.foo
}
}
在組件中,我從計算中呼叫它:
computed: {
...mapGetters(['getFoo']),
}
我在模板中的 if 中使用該變數:
<template>
<template v-if="foo">
<span>Bar</span>
</template>
</template>
在控制臺中,我收到以下警告: [Vue warn]: Property "foo" was accessed during render but is not defined on instance.
我試圖在沒有吸氣劑的情況下做到這一點,但我收到了同樣的警告:
computed: {
getFoo() {
return this.$store.getters.getFoo;
}
}
uj5u.com熱心網友回復:
由于您在計算選項中映射 getter,因此您應該使用 getter name getFoo:
<template>
<template v-if="getFoo">
<span>Bar</span>
</template>
</template>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/328302.html
標籤:javascript Vue.js Vuex
上一篇:認知事件后不觸發Lambda函式
