0π
First, ensure your Vuex module is namespaced:
// store/characters.ts
export default {
namespaced: true, π
getters: {
getSearchPhrase: state => state.searchPhrase
},
//...
}
// store/index.ts
import Vue from 'vue'
import Vuex from 'vuex'
import characters from './characters'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
characters
}
})
Then, use the vuex-class
namespace
helper to access the namespaced getter:
import Vue from 'vue'
import { Getter, namespace } from 'vuex-class'
import Component from 'vue-class-component'
const characters = namespace('characters') π
@Component
export class MyComp extends Vue {
@characters.Getter('getSearchPhrase') π
searchPhrase !: string;
//...
}
Source:stackexchange.com