ES2015论证解构错误

时间:2017-09-02 10:52:56

标签: javascript ecmascript-6

我正在尝试解构以下功能:

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 ;

我的编码出了什么问题? 感谢您的反馈

1 个答案:

答案 0 :(得分:1)

剪切和粘贴问题,忘记编写导出语句 它以这种方式运行:

import { CHANGE_MSG, INCREMENT_COUNTER } from './mutation_types'

export default {
  changeMessage ({ commit }, msg) {
    commit(CHANGE_MSG, msg)
  },
  incrementCounter ({ commit }) {
    commit(INCREMENT_COUNTER)
  }

}