在项目更目录新建store模块,新建store.js


//store   store.js   
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
state: {
author: 'Youngmon'
},
mutations: {
author(state, newName) {
state.author = newName;
}
},
actions: { }
})

export default store

/**
//main.js 新增
import store from './store'
Vue.prototype.$store = store




//demo.vue
this.$store.commit("author","yongmao");


computed: {
author() {
return this.$store.state.author
}
}




*/