解决vuex辅助函数在mpvue中不能使用的问题
vuex的辅助函数 mapState、mapGetters、mapMutations、mapActions但在mpvue中不能使用vuex的辅助函数,什么原因呢?store对象不能注入到子组件中,在子组件中不能使用this.$store。如果使用了vuex辅助函数mapMutations与mapGetters,则在子组件中会报如下的错误:解决方法:将store对象通过$stor...
·
vuex的辅助函数 mapState、mapGetters、mapMutations、mapActions
但在mpvue中不能使用vuex的辅助函数,什么原因呢?
store对象不能注入到子组件中,在子组件中不能使用this.$store。如果使用了vuex辅助函数mapMutations与mapGetters,则在子组件中会报如下的错误:

![]()
解决方法:
将store对象通过$store属性添加到vue原型上,即:Vue.prototype.$store = store
在main.js中,需要做一些更改:
import Vue from 'vue'
import App from './App'
import store from './store'
Vue.prototype.$store = store
Vue.config.productionTip = false
App.mpType = 'app'
new Vue({
store
}).$mount()
更多推荐



所有评论(0)