Many pages or components to call the state, of vuex how to write the best ah?

store I used two modules, / store/index.js is as follows:

import Vue from "vue";
import Vuex from "vuex";
import app from "./modules/app";
import user from "./modules/user";

Vue.use(Vuex);

const store = new Vuex.Store({
  modules: {
    app,
    user
  }
});

export default store

/ store/modules/app.js is as follows:

const app = {
  state: {
    skills: null //
  },
  mutations: {},
  actions: {},
  getters:{}
}

export default app;

now I refer to the status directly in the data of all pages or components, such as

export default {
  data() {
    skills: this.$store.state.app.skills,
  }
}

this works, but is it reasonable?

I tried using

on the page.
import { mapGetters } from "vuex"
export default {
  computed: {
    ...mapGetters(["skills"]),
  },
}

this seems to be in line with the specification, but do you need to write all the properties of states in getters once return?? Feel redundant, huh?
I am grateful for your advice.

Mar.29,2021

use mapState?


use mapGetters!

Menu