mpvue - vuex辅助函数报错:Cannot read property 'commit' undefined

前言

    在mpvue中,vuex对象不能注入到页面和组件当中
    如果使用了vuex辅助函数mapMutations与mapGetters,则在子组件中会报如下的错误:
在这里插入图片描述

解决方法:

    将store对象通过$store属性添加到vue原型上,即:

Vue.prototype.$store = store

在main.js中,需要做一些更改:

import store from './store'
Vue.prototype.$store = store

你可能感兴趣的:(mpvue,vuex,commit,undefined,mpvue)