简单使用vuex状态管理的mapState和mapMutations

store.js

import Vue from ‘vue’
import Vuex from ‘vuex’

Vue.use(Vuex)

export default new Vuex.Store({
state: {
cityName:“张三”
},
mutations: {
changeStr(state,cName){
state.cityName=cName
}
},
actions: {

}
})

app.vue

{ {$store.state.cityName}} // 最原始的写法
{ {cityName}}

你可能感兴趣的:(vue笔记)