引入vuex的store状态后报警告

安装vuex:

npm install --save vuex

 

在src文件夹下新建store文件夹,在store文件夹下建index.js文件,index.js文件内容:

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {}
const store = new Vuex.Store({
    state,
    mutations: {},
    getters: {},
    actions: {},
    modules: {}
})
export default store

 

在main.js文件下引入和声明store:

import Vue from 'vue'
import App from './App'
import router from './router'
// 引入样式
import './styles/style.scss'
import store from './store/index' // 引入store

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store, 
  components: { App },
  template: '<App/>'
})

 

保存后报出4个警告:

 

 

原因:

安装vuex时默认安装了最新版,即4.0版本,但项目用的是vue2.0,vue和vuex版本对不上。

 

解决方法:

安装vuex3.0版:npm install --save vuex@3

posted @ 2022-02-08 16:25  WillaWilla  阅读(179)  评论(0编辑  收藏  举报