没有Object.assign使用mapActions错误?

时间:2017-03-02 10:18:11

标签: webpack vue.js vuex

x.vue文件

methods: {
    ...mapActions([
      'fetchTopicVideo',
    ]),
}

这将是抛出错误,错误信息是:

ERROR in ./~/buble-loader!./~/vue-loader/lib/selector.js?

type=script&index=0!./src/components/CardList.vue
Module build failed:
43 :     // }, (res) => {
44 :     //   console.log('query error')
45 :     // })
46 :   },
47 :   methods: {
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Object spread operator requires specified objectAssign option with 'Object.assign' or polyfill helper. (47:11)
 @ ./src/components/CardList.vue 7:2-105
 @ ./~/buble-loader!./~/vue-loader/lib/selector.js?type=script&index=0!./src/views/ClientTopicShare.vue
 @ ./src/views/ClientTopicShare.vue
 @ ./src/router/index.js
 @ ./src/app.js
 @ ./src/client-entry.js
 @ multi webpack-hot-middleware/client ./src/client-entry.js

但是下面的代码不会抛出错误:

methods: Object.assign({},
   mapActions([
     'fetchTopicVideo'
   ])
)

.babelrc文件:

{
  "presets": ["es2015", "stage-2"],
  "plugins": ["transform-runtime"],
  "comments": false
}

也许巴贝尔失败导致这一点。

1 个答案:

答案 0 :(得分:1)

问题由https://github.com/vuejs/vue-hackernews-2.0/issues/87

解决

安装buble,编辑vue-loader.config.js

module.exports = {
    ...
    buble: {
        objectAssign: 'Object.assign',
    },
}