import {ADD_ITEM, DELETE_ITEM, SELECT_ALL_ITEMS, DELETE_COMPLETE_ITEMS} from './mutation-types'
export default {
addItem ( {commit}, item) {
//提交对mutation的请求
commit( 'ADD_ITEM', {item})
},
deleteItem ( {commit}, index) {
//提交对mutation的请求
commit( 'DELETE_ITEM', {index})
},
selectAllItems ( {commit}, checked) {
//提交对mutation的请求
commit( 'SELECT_ALL_ITEMS', {checked})
},
deleteCompleteItems ( {commit},) {
commit( 'DELETE_COMPLETE_ITEMS' )
}
}
昨天在写一个demo的时候报了一个错 [vuex] unknown mutation type
找了半天也没有发现问题根源所在
今天看到actions对象模块中,也就是上面这串代码里mutation常量被我裹了引号
正确写法是如下
import {ADD_ITEM, DELETE_ITEM, SELECT_ALL_ITEMS, DELETE_COMPLETE_ITEMS} from './mutation-types'
export default {
addItem ( {commit}, item) {
//提交对mutation的请求
commit( ADD_ITEM, {item})
},
deleteItem ( {commit}, index) {
//提交对mutation的请求
commit( DELETE_ITEM, {index})
},
selectAllItems ( {commit}, checked) {
//提交对mutation的请求
commit( SELECT_ALL_ITEMS, {checked})
},
deleteCompleteItems ( {commit},) {
commit( DELETE_COMPLETE_ITEMS )
}
}
碰到的坑分享出来~