文章目录
- 1、出现的问题
- 2、问题原因
- 3、错误代码还原
- 4、解决方法
- 5、成功解决
1、出现的问题
![在这里插入图片描述 成功解决:[vuex] must call Vue.use(Vuex) before creating a store instance._错误代码](https://file.cfanz.cn/uploads/png/2022/09/02/22/9786a2JL56.png)
2、问题原因
在创建store的时候、要先声明使用vuex。就是先后问题、使用顺序出现问题
3、错误代码还原
注意:在main.js中调整Vue.use(Vuex)和import store from './store/index.js'的先后顺序是没有用的。原因是:代码的执行机制是先扫描这个文件,首先执行所有的import
![在这里插入图片描述 成功解决:[vuex] must call Vue.use(Vuex) before creating a store instance._错误代码_02](https://file.cfanz.cn/uploads/png/2022/09/02/22/S834403e32.png)
![在这里插入图片描述 成功解决:[vuex] must call Vue.use(Vuex) before creating a store instance._错误代码_03](https://file.cfanz.cn/uploads/png/2022/09/02/22/9GL1TG0N7H.png)
4、解决方法
将Vue.use(Vuex)直接放在store/index.js文件中
![在这里插入图片描述 成功解决:[vuex] must call Vue.use(Vuex) before creating a store instance._vue.js_04](https://file.cfanz.cn/uploads/png/2022/09/02/22/Ra71Fb20C6.png)
![在这里插入图片描述 成功解决:[vuex] must call Vue.use(Vuex) before creating a store instance._vue.js_05](https://file.cfanz.cn/uploads/png/2022/09/02/22/39Aef7Y17M.png)
5、成功解决
![在这里插入图片描述 成功解决:[vuex] must call Vue.use(Vuex) before creating a store instance._错误代码_06](https://file.cfanz.cn/uploads/png/2022/09/02/22/9R5MZT0dLF.png)
![在这里插入图片描述 成功解决:[vuex] must call Vue.use(Vuex) before creating a store instance._解决方法_07](https://file.cfanz.cn/uploads/png/2022/09/02/22/aK8677a508.png)








