伤心了难过了,一个人静静,不要在任何人面前掉眼泪,我不能原谅我的懦弱。经常笑,学会向比自己小的人称哥,以保持年轻心态。
使用场景
当需要进行vuex进行数据状态管理的时候,会使用到mapGetters,mapState,还有自身的计算属性的时候,这个时候就会用到这个了!
1.首先需要安装
npm install babel-plugin-transform-object-rest-spread -D
2.需要在.babelrc文件中新增以下
{ "presets": [ ["env", { "modules": false }] ], "plugins": ["transform-object-rest-spread"] //增加这一行 }
3.在vue组件中使用
<script> import {mapState,mapGetters} from 'vuex' export default { methods:{ increment(){ this.$store.commit('increment'); } }, computed:{ ...mapGetters([ 'count' ]), ...mapState({ counts(){ return this.$store.state.count; } }) } } </script>
以上就是vuex中如何使用对象展开运算符的示例。这一路,很累很累,满身伤痕,懂得了谁才是你要珍惜的人,有些人注定是路人。更多关于vuex中如何使用对象展开运算符的示例请关注haodaima.com其它相关文章!