美文网首页
Vue中两种方式使用store的state和action

Vue中两种方式使用store的state和action

作者: leslie1943 | 来源:发表于2019-03-21 11:15 被阅读0次

更推荐读一下这篇文章(更简洁,更容易移植!)

🚀 https://www.jianshu.com/p/7a0e1330faac 🚀

import { mapState ,mapActions} from 'vuex'
export default {
    methods:{
        // 格式:mapActions(namespace,[actionName])
        ...mapActions('home', ['getHomeData']),
        ...mapActions('dictionary', ['getSubCertType']),
    },
    computed: {
        // 方式一: 格式: stateName: state => state.namespace.stateName,
        ...mapState({
            homeData: state => state.home.homeData,
            subCertType: state => state.dictionary.subCertType
        }),
        // 方式二: 格式: ...mapState(namespace,{ stateName : state => state.stateName}),
        ...mapState('home',{ homeData : state => state.homeData}),
        ...mapState('dictionary',{ subCertType : state => state.subCertType})
    }
}

相关文章

网友评论

      本文标题:Vue中两种方式使用store的state和action

      本文链接:https://www.haomeiwen.com/subject/yjqqvqtx.html