搜索

首页  >  问答  >  正文

javascript - vuex的mapState与其它computed属性共存的正确写法是?

mapState的官方示例使用方法是:

computed:mapState(['count'])

那其它不需要state的computed属性应该怎么写呢?我试了

computed:{mapState(['count']), age(){return this.old_age + 1;}}

会报错

computed:mapState(['count', age(){return this.old_age + 1;}])

也会报错,甚至

computed:{mapState(['count'])}

都会报错 请问正确的写法应该是怎样的?

为情所困为情所困2832 天前914

全部回复(1)我来回复

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:26:52

    提问之前能不能看看vuex官方文档?
    computed: { localComputed () { / ... / },
    // 使用对象展开运算符将此对象混入到外部对象中
    ...mapState({ // ... })
    }
    如果不知道对象展开运算符是什么麻烦去查es6/7的文档

    回复
    0
  • 取消回复