mapState的官方示例使用方法是:
computed:mapState(['count'])
那其它不需要state的computed屬性應(yīng)該怎么寫(xiě)呢?我試了
computed:{mapState(['count']), age(){return this.old_age + 1;}}
會(huì)報(bào)錯(cuò)
computed:mapState(['count', age(){return this.old_age + 1;}])
也會(huì)報(bào)錯(cuò),甚至
computed:{mapState(['count'])}
都會(huì)報(bào)錯(cuò) 請(qǐng)問(wèn)正確的寫(xiě)法應(yīng)該是怎樣的?
提問(wèn)之前能不能看看vuex官方文檔?
computed: { localComputed () { / ... / },
// 使用對(duì)象展開(kāi)運(yùn)算符將此對(duì)象混入到外部對(duì)象中
...mapState({ // ... })
}
如果不知道對(duì)象展開(kāi)運(yùn)算符是什么麻煩去查es6/7的文檔