您好,欢迎来到九壹网。
搜索
您的当前位置:首页vuex中使用对象展开运算符的示例

vuex中使用对象展开运算符的示例

来源:九壹网


使用场景

当需要进行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> 

Copyright © 2019- 91gzw.com 版权所有 湘ICP备2023023988号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务