[英]NuxtJs Computed property “isLoggedIn” was assigned to but it has no setter
For some reason i keep getting this error no matter what I try.出于某种原因,无论我尝试什么,我都会不断收到此错误。
This is how I'm getting and updating the computed property这就是我获取和更新计算属性的方式
computed: {
isLoggedIn() {
return this.$store.state.user.isLoggedIn;
}
},
methods: {
handleAuthenticate(value) {
this.$store.commit("user/authenticate", value);
}
}
I've already looked up similar answers here and this doesn't fix the issue我已经在这里查找了类似的答案,但这并不能解决问题
computed: {
isLoggedIn: {
get() {
return this.$store.state.user.isLoggedIn;
},
set(newValue) {
this.$store.commit("user/authenticate", newValue);
}
}
},
I'm wondering if this is because I'm using Nuxt instead of just plain Vuejs.我想知道这是否是因为我使用的是 Nuxt 而不是普通的 Vuejs。 I followed the example on Nuxt official doc but still getting the error everytime i call my
handleAuthenticate
method:我按照 Nuxt 官方文档中的示例进行操作,但每次调用我的
handleAuthenticate
方法时仍然出现错误:
https://nuxtjs.org/examples/vuex-store/ https://codesandbox.io/s/github/nuxt/nuxt.js/tree/dev/examples/vuex-store?from-embed https://nuxtjs.org/examples/vuex-store/ https://codesandbox.io/s/github/nuxt/nuxt.js/tree/dev/examples/vuex-store?from-embed
this is the structure of my current user state and mutations这是我当前用户 state 和突变的结构
state.js state.js
export default () => ({
isLoggedIn: false
})
mutations.js突变.js
export default {
authenticate(state, value) {
state.isLoggedIn = value;
}
}
getters.js getters.js
export default {
isLoggedIn(state) {
return state.isLoggedIn
}
}
i'm not exactly sure what the problem is as i followed the example.我不完全确定问题是什么,因为我遵循了这个例子。 Maybe i missed something.
也许我错过了什么。 Any help would be appreciated.
任何帮助,将不胜感激。 thanks!
谢谢!
for those who encountered a similar issue.对于那些遇到类似问题的人。 It turns I was received the error because i was using the
isLoggedIn
with v-model property.原来我收到了错误,因为我正在使用带有 v-model 属性的
isLoggedIn
。
<v-navigation-drawer
v-model="isLoggedIn"
:mini-variant="miniVariant"
:clipped="clipped"
fixed
app
>
</v-navigation-drawer>
I fixed it by returning the value on set method我通过返回 set 方法的值来修复它
isLoggedIn: {
get() {
return this.$store.state.user.isLoggedIn;
},
set(val) {
return val;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.