zoukankan      html  css  js  c++  java
  • Vue2.3.3中使用对象展开运算符出错

    在vue应用中使用vuex中的...mapGetters时得到如下错误:

    <script>
      import VLink from '../components/VLink.vue'
      import store from '../vuex/store';
      import { mapGetters } from 'vuex';
    
      export default {
        store,
        components: {
          VLink
        },
        computed: {
          // 使用对象展开运算符将 getter 混入 computed 对象中
          ...mapGetters([
            'doneTodos',
            'totalDone',
            // ...
          ]),
          count() {
            return this.$store.state.count;
          },
        },
        methods: {
          increment() {
            this.$store.commit('increment');
          },
          decrement() {
            this.$store.commit('decrement');
          }
        }
      }
    </script>

    错误:

    ... unexpected token

    解决方法:

    这里的 ...是es6的对象扩容运算符,目前bable暂不支持,需要引入新的包来解决

    1. npm install babel-plugin-transform-object-rest-spread --save-dev
    2. 到根目录修改.babelrc文件
    // .babelrc 文件
      "plugins": ["transform-object-rest-spread"] //新增这一行

    每天一点点
  • 相关阅读:
    py3学习笔记0(入坑)
    为什么很多PHP文件最后都没有?>
    作业
    凯撒密码、GDP格式化输出、99乘法表
    作业4
    作业3
    turtle库基础练习
    作业2
    作业1
    编译原理有限自动机的构造与识别
  • 原文地址:https://www.cnblogs.com/juliazhang/p/11340366.html
Copyright © 2011-2022 走看看