我有一个vuex商店,如下所示:
import spreeApi from '../../gateways/spree-api'
// initial state
const state = {
products: [],
categories: []
}
// mutations
const mutations = {
SET_PRODUCTS: (state, response) => {
state.products = response.data.products
commit('SET_CATEGORIES')
},
SET_CATEGORIES: (state) => {
state.categories = state.products.map(function(product) { return product.category})
}
}
const actions = {
FETCH_PRODUCTS: (state, filters) => {
return spreeApi.get('products').then(response => state.commit('SET_PRODUCTS', response))
}
}
export default {
state,
mutations,
actions
}
我想称呼mutation:SET_CATEGORIES
from突变:SET_PRODUCTS
,但这给了我错误:
projectFilter.js:22未捕获(承诺中)ReferenceError:未定义提交(…)
什么应该是正确的方法来做到这一点。我尝试了store.commit
和this.commit
,但是这些也给出了类似的错误。