<script>
computed: {
loggedOut () {
return this.$store.state.login.logged
}
},
signin (store) {
this.$auth.loginWith('local', {...code}
}).then(this.$store.commit.login('login/LOGGED_IN')) // <- error in commit
}
}
}
</script>
我检索loggingOut()计算属性,但是当我尝试通过提交来对其进行变异时,它给我一个错误:
[vuex]未知突变类型:登录名/ LOGGED_IN
我的login.js文件:
export const state = () => ({
logged: false
})
export const mutations = () => ({
LOGGED_IN (state) {
state.logged = true
},
LOGGED_OUT (state) {
state.logged = false
}
})
index.js文件:
export const state = () => ({
})
export const mutations = {
}
应该工作
this.$store.commit('login/LOGGED_IN')
因为Nuxt.js默认store / xxx.js(除index.js以外的每个.js文件)是一个模块,所以您需要使用模块方式来调用它