我正在尝试解构以下功能:
import { CHANGE_MSG, INCREMENT_COUNTER } from './mutation_types'
export const changeMessage = (store, msg) => {
store.commit(CHANGE_MSG, msg)
}
这样:
// ES2015 arguments destructuring
changeMessage ({ commit }, msg) {
commit (CHANGE_MSG, msg)
}
但是,'{'
会引发错误Parsing error: unexpected token , [js] expected ;
我的编码出了什么问题? 感谢您的反馈
答案 0 :(得分:1)
剪切和粘贴问题,忘记编写导出语句 它以这种方式运行:
import { CHANGE_MSG, INCREMENT_COUNTER } from './mutation_types'
export default {
changeMessage ({ commit }, msg) {
commit(CHANGE_MSG, msg)
},
incrementCounter ({ commit }) {
commit(INCREMENT_COUNTER)
}
}