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

mac2024-10-04  52

前言

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

解决方法:

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

Vue.prototype.$store = store

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

import store from './store' Vue.prototype.$store = store
最新回复(0)