Vue之vue项目引入vuex

1、首先给项目安装依赖

npm install vuex --save

2、新建仓库

在src目录下新建一个文件夹,命名为store,然后在该文件夹下面创建一个js文件store.js。

3、新建仓库在项目中引入
//在main.js中
import store from './store/store'
new Vue({
  el: '#app',
  router,
  store,  //使用store
  components: { App },
  template: '<App/>'
})
4、store.js文件
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
const state = { }

const mutations = { }

const actions = { }

export default new Vuex.Store({
  state,
  mutations,
  actions
})

猜你喜欢

转载自blog.csdn.net/weixin_40736319/article/details/89379474