import pano from './module/pano'
export const store = new Vuex.Store({
modules: {
pano
}
})
// pano.js
const state = {
pano: null
}
此时,获取state的时候是this.$store.state.pano.pano.xxx,如何才能去除一层pano?
目前其中一个方法是在pano.js里,如下这样书写,但是我的字段太多了
// pano.js
const state = {
key1: '',
key2: ''
}
还是用for in遍历?
// pano.js
const state = {
}
const mutations = {
updatePano: (state, payload) => {
for (const key in payload) {
state[key] = payload[key]
}
}
}
用
mapState
简写使用
this.pano.xxx