vuex中,有默认的五种基本的对象:
在项目中创建store.js 引入vuex并export出。
1 import Vue from ‘vue‘ 2 import Vuex from ‘vuex‘ 3 4 Vue.use(Vuex) 5 6 const state = { 7 count: 0 8 } 9 10 export default new Vuex.Store({ 11 state 12 })
mian.js中引入store
1 import Vue from ‘vue‘ 2 import App from ‘./App‘ 3 import router from ‘./router‘ 4 import store from ‘./vuex/store‘ // 引入store 5 Vue.config.productionTip = false 6 7 /* eslint-disable no-new */ 8 new Vue({ 9 el: ‘#app‘, 10 router, 11 store, 12 components: { App }, 13 template: ‘<App/>‘ 14 })
可以创建vue实例并使用vue了
原文:https://www.cnblogs.com/shenyouhyh/p/14985897.html