1:新建store文件夹,用来保存.js文件
2:index.js中的内容
import Vuefrom 'vue'
import Vuexfrom 'vuex'
import statefrom './state'
import mutationsfrom './mutation'
Vue.use(Vuex)
export default new Vuex.Store({
state,
mutations
})
3:state.js中的内容
const state = {
houseContent:'迩伶贰blog'
}
export default state
4:mutations.js中的内容
const mutations = {
increment (state, result) {
state.houseContent = result
}
}
export default mutations
5:在全局main.js中引入:
6:使用:
取值:let house =this.$store.state.houseContent
赋值:this.$store.commit('increment', result)