- Cannot assign to read only property 'exports' of object '#<Object>'
原因:webpack 2中不允許混用import和module.exports。在js文件中可以混用require和export。但是不能混用import 以及module.exports。
解決辦法:統(tǒng)一改成ES6的方式編寫:不使用module.exports,使用export/export default。
- Cannot read property 'getters' of undefined
原因:類似于找不到getters,actions,mutations之類的,甚至有遇到mapGetters找不到,很多情況是:
import * as actions from './actions';
import * as getters from './getters';
或者:
import { mapActions, mapGetters } from 'vuex';
以上代碼沒有寫對。
我遇到的問題是因為在我的目錄結(jié)構(gòu)下store是我自己建的一個文件夾,而用vue create命令初始化下來的項目本身有store.js文件,我在main.js中引用方式是:
import store from './store';
所以導(dǎo)致去尋找store.js,而沒有找到store目錄下的index.js。
解決辦法:單獨寫了store,就把store.js刪掉。