import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './action'
import getters from './getters'
Vue.use(Vuex)
const state = {
userInfo: { phone: 111 }, //用戶信息
orderList: [{ orderno: '1111' }], //訂單列表
orderDetail: null, //訂單產(chǎn)品詳情
login: false, //是否登錄
}
export default new Vuex.Store({
state,
getters,
actions,
mutations,
})
computed: {
...mapState([
'orderList',
'login'
]),
},
mounted(){
console.log(typeof orderList); ==>undefind
console.log(typeof this.orderList)==>object
}
mapState通過擴(kuò)展運算符將 store.state.orderList 映射 this.orderList 這個this 很重要尤泽,這個映射直接映射到當(dāng)前Vue的this對象上。
所以通過this都能將這些對象點出來规脸,同理坯约,mapActions, mapMutations都是一樣的道理。牢記~~~