【问题标题】:ES2015 arguments destructuring errorES2015 参数解构错误
【发布时间】:2017-09-02 10:52:56
【问题描述】:

我也在尝试解构以下函数:

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)
}

但是 eslint 在 '{' 上引发错误

Parsing error: unexpected token , [js] expected ;

我的编码有什么问题? 感谢反馈

【问题讨论】:

  • 它是否有效,只是一个 linting 错误,还是根本无效?
  • 这不等价,你会在commit中失去this
  • 除此之外,对我有用:repl.it/Kdaw
  • 抱歉 .. 知道了 .. 忘记导出了!看我的回答..以这种方式解构是可以的..享受你的一天!

标签: javascript ecmascript-6


【解决方案1】:

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

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

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    • 2015-03-02
    相关资源
    最近更新 更多