我的 vuex 商店中有一个 firestore 绑定,一个前端元素依赖于它。这是一些示例代码:
Vue模板:
<v-list-item
v-if="dependantGetter"
@click="doSomething()">
<v-list-item-title>Do something</v-list-item-title>
</v-list-item>
Vue 脚本:
computed: {
...mapGetters(["dependantGetter"]),
}
Vuex商店:
const state = {
settings : [],
}
const getters = {
dependantGetter: ({ settings }) => {
let check = settings.filter(setting => setting.id === 'idName')
return check[0].startSync
}
}
但我遇到的问题是,浏览器会抛出多个错误,直到绑定变为true
or false
:
[Vue warn]: Error in render: "TypeError: Cannot read property 'startSync' of undefined"
TypeError: Cannot read property 'startSync' of undefined
[Vue warn]: Error in render: "TypeError: Cannot read property 'startSync' of undefined"
TypeError: Cannot read property 'startSync' of undefined
[Vue warn]: Error in render: "TypeError: Cannot read property 'startSync' of undefined"
TypeError: Cannot read property 'startSync' of undefined
到目前为止,我的解决方案是从内部返回这样的吸气剂vuex
,但这对我来说真的不合适
return check[0] == undefined ? false : check[0].startSync
或者,在使用 firebase 和 vuexfire 时,这是返回东西的正确方法吗?