Vuex namespaced

import pano from "./module/pano"
export const store = new Vuex.Store({
  modules: {
    pano
  }
})
// pano.js
const state = {
  pano: null
}

at this point, when getting state, it is this.$store.state.pano.pano.xxx. How can I remove a layer of pano?
one of the current methods is in pano.js, which is written like this, but I have too many fields

// pano.js
const state = {
  key1: "",
  key2: ""
}

or do you want to traverse with for in?

// pano.js
const state = {
}
const mutations = {
  updatePano: (state, payload) => {
    for (const key in payload) {
      state[key] = payload[key]
    }
  }
}
May.25,2022

should not be lost, the first layer represents the module name, the second layer represents the attribute name, if you think it is long, use mapState.


use mapState abbreviation

computed: {
    ...mapState('pano', ['pano'])
}

use
this.pano.xxx

Menu