如何使用object spread / mapState helper

时间:2017-10-31 08:21:41

标签: javascript webpack vuejs2 vuex

我正在尝试在Vue页面中映射我的商店的状态变量:

<script>
    export default {
        data: () => ({
            localData: []

        }),
        computed: {  
            someLocalProperty: {
                get: function () {
                  // ....
                }
            },
            ...mapState({
                one: state => state.one,
                two: state => state.two,
                three: state => state.three, 
            })
        },                   
    };
</script>

然而,这给了我以下错误:

   Uncaught Error: Module build failed: 
    71 :     data: () => ({
    72 :         localData: []
    73 : 
    74 :     }),
    75 :     computed: {

    Object spread operator requires specified objectAssign option with 'Object.assign' or polyfill helper. (75:14)

我做错了什么?

我尝试将objectAssign: 'Object.assign'添加到我的webpack配置中,但它没有帮助:

rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
            objectAssign: 'Object.assign',
            preLoaders: {
            i18n: 'yaml-loader'
          },
          loaders: {
            i18n: '@kazupon/vue-i18n-loader'
          }
        }
      },
      {
        test: /\.js$/,
        loader: 'buble-loader',
        exclude: /node_modules/,
        options: {
          objectAssign: 'Object.assign'
        }
      },
      {
        test: /\.styl$/,
        loader: ['style-loader', 'css-loader', 'stylus-loader']
      },
      {
        test: /\.(eot|svg|ttf|woff|woff2)$/,
        loader: 'file-loader?name=public/fonts/[name].[ext]'
      }
    ]
  },

1 个答案:

答案 0 :(得分:0)

也许你的buble-loader配置错了?

original project documentation

中查看此代码段
public class MaxAndMin
 {
  public static void main(String[] args)
    {

int length = args.length;
int[] array = new int[length];


for (int i = 0; i < length; i++) {
  array[i] = Integer.parseInt(args[i]);
}
  double max = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < length; i++) {
      if (array[i] > max) max = array[i];
  }  
   System.out.println(max);

 }  
}