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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章