您的位置:首頁技術文章
文章詳情頁

javascript - vuex的mapState與其它computed屬性共存的正確寫法是?

瀏覽:106日期:2023-09-24 08:19:24

問題描述

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’])}

都會報錯 請問正確的寫法應該是怎樣的?

問題解答

回答1:

提問之前能不能看看vuex官方文檔?computed: { localComputed () { / ... / }, // 使用對象展開運算符將此對象混入到外部對象中 ...mapState({ // ... }) }如果不知道對象展開運算符是什么麻煩去查es6/7的文檔

標簽: JavaScript
相關文章:
国产综合久久一区二区三区