更推荐读一下这篇文章(更简洁,更容易移植!)
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})
}
}
网友评论