[英]How to correctly use Nuxt / Vue ...mapMutations
I'm trying to use ...mapMutations
with Vuex modules in Nuxt.我正在尝试将
...mapMutations
与 Nuxt 中的 Vuex 模块一起使用。 My call to this.setDates(dates)
results in an error:我对
this.setDates(dates)
调用导致错误:
this.setDates is not a function
this.setDates 不是函数
In my Nuxt store: store/header.js
在我的 Nuxt 商店中:
store/header.js
export const mutations = {
setDates(state, dates) {
state.dates = dates;
},
}
In my component在我的组件中
methods: {
...mapMutations(
{'header': ['setDates']},
),
changeDate(dates) {
this.setDates(dates);
}
}
This will try to create a method called header
using the mutation setDates
:这将尝试使用突变
setDates
创建一个名为header
的方法:
mapMutations(
{'header': ['setDates']},
)
I believe what you want is:我相信你想要的是:
mapMutations('header', ['setDates'])
This will treat header
as a namespace instead.这会将
header
视为命名空间。
You map your mutation as header, i think u need call header() instead of this.setDates()您将您的突变映射为标题,我认为您需要调用 header() 而不是 this.setDates()
from https://vuex.vuejs.org/guide/mutations.html来自https://vuex.vuejs.org/guide/mutations.html
...mapMutations({
add: 'increment' // map `this.add()` to `this.$store.commit('increment')`
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.