简体   繁体   English

NuxtJs 计算属性“isLoggedIn”已分配给但它没有设置器

[英]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.

相关问题 已分配计算属性,但它没有设置器 - 切换组件 - Computed property was assigned to but it has no setter - a toggle component Vue警告:已分配计算属性“projectName”,但没有设置器 - Vue warn: Computed property “projectName” was assigned to but it has no setter 如何解决分配给计算属性“搜索”但没有设置器的问题? - How can I solve Computed property "search" was assigned to but it has no setter? Nuxtjs和Axios上的计算属性? - Computed property on Nuxtjs and Axios? 如何在将 element-ui 与 VueJs 一起使用时在控制台中消除此错误“计算属性 validateState 已分配给但它没有设置器” - How do I get rid of this error "Computed property validateState was assigned to but it has no setter" in the console while using element-ui with VueJs Ember 3计算的属性获取器设置器 - Ember 3 computed property getter setter Vuejs,带有setter冻结组件的计算属性 - Vuejs, computed property with setter freeze component 如何将Vuex与异步计算的setter属性一起使用 - How to use Vuex with asynchronous computed setter property 如何在计算属性内使用window.innerWidth-NuxtJS - how to use window.innerWidth within computed property - NuxtJS 无法读取未定义的属性“isLoggedIn” - Cannot read property 'isLoggedIn' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM