今天在写vuex的时候遇到了一个特别无语的问题,找了半个小时才找到这个问题,所以贴出来,大家在遇到和我一样的问题的时候不会太过慌张
在第一次写vuex的时候无论如何获取不到$store,后来找了好久才发现是我给全局VUE注入的时候注入的是Store而非store
这一个字母之差看上去可能没什么问题,可就是获取不到全局的$store;
代码奉上
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from \'vue\' import App from \'./App\' import router from \'./router\' import font from \'./static/js/font.js\'; import \'./static/scss/animate.css\' Vue.config.productionTip = false import Store from \'./store/store.js\'; /* eslint-disable no-new */ new Vue({ el: \'#app\', router, Store, components: { App }, template: \'<App/>\' })
我之前就是这么写的,所以一直出不来,可是逻辑根本没有问题
之后我把大写的S换成了小写的s就出来了
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from \'vue\' import App from \'./App\' import router from \'./router\' import font from \'./static/js/font.js\'; import \'./static/scss/animate.css\' Vue.config.productionTip = false import store from \'./store/store.js\'; /* eslint-disable no-new */ new Vue({ el: \'#app\', router, store, components: { App }, template: \'<App/>\' })
以上这篇VUEX采坑之路之获取不到$store的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
© 版权声明
THE END
暂无评论内容