Vue 教程第十三篇—— Vuex 之 state
Vuex——state访问
方法一、直接获取
<span>{{$store.state.count}}</span>
方法二、通过 computed 的计算属性直接赋值
<span>{{count}}</span> <script type="text/javascript"> computed: { count(){ return this.$store.state.count } } </script>
方法三、通过 mapState 的计算属性直接赋值
<span>{{count}}</span> <script type="text/javascript"> import {mapState} from 'vuex'; computed: mapState({ count: state => state.count }) </script>
方法四、通过 mapState 的数组来赋值
<span>{{count}}</span> <script type="text/javascript"> import {mapState} from 'vuex'; computed: mapState(['count']) </script>
方法五、对象展开运算符
<span>{{count}}</span> <script type="text/javascript"> import {mapState} from 'vuex'; computed: { ...mapState({ count: state => state.count }) } </script>
相关推荐
CSCCockroach 2020-09-15
lbPro0 2020-07-05
MrSunOcean 2020-06-21
lylwanan 2020-06-14
Callmesmallpure 2020-05-31
ShaLiWa 2020-05-25
墨龙吟 2020-04-24
MrSunOcean 2020-04-24
H女王范儿 2020-04-22
lbPro0 2020-04-16
ShaLiWa 2020-02-29
ShaLiWa 2020-01-17
MrSunOcean 2020-01-03
lbPro0 2020-01-01
H女王范儿 2019-12-29