vuex 获取state中的状态
2017-08-21 22:38:37 作者:yxl 次阅读 vue
模板获取vuex states中的值
1、直接通过
{{ $store.state.count}}
2、通过computed计算属性来
computed:{
1、直接通过
{{ $store.state.count}}
2、通过computed计算属性来
computed:{
count(){
return this.$store.state.count
}
},
3、使用mapState的方法
3、使用mapState的方法
<script>
import store from "@/vuex/store";
import { mapState } from 'vuex';
export default{
data(){
return {
msg:'初次使用vuex'
}
},
computed:mapState({
count:state=>state.count
}),
store
}
</script>
4、使用mspState数组的方式 (常用)
4、使用mspState数组的方式 (常用)
<script>
import store from "@/vuex/store";
import { mapState } from 'vuex';
export default{
data(){
return {
msg:'初次使用vuex'
}
},
computed:mapState(['count']),
store
}
</script>
凡本站注明“本站”或“投稿”的所有文章,版权均属于本站或投稿人,未经本站授权不得转载、摘编或利用其它方式使用上述作品。
编辑:yxl
关键词:
相关阅读:
- 1vue+better-scroll 下拉刷新,上拉加载更多2018.08.09
- 2vue-cli全局引入公用scss文件2018.08.08
- 3vue中Axios的封装和API接口的管理2018.08.08
- 4vue2单元测试环境搭建2018.08.06
- 5vue.js 使用中踩过的坑2018.07.22