Is there any progress?
Closed this issue · 2 comments
Is there any progress?
// store/modules/product
export interface ProductState {
name: string
price: number
}
const state: ProductState = {
name: '',
price: 0
}
What can I do to know the state type in the Vue component?
@State(state => state.product.name) productName // can be inferred to be a string
ModuleA.ts
`interface ModuleA {
name: string;
hobby: string[];
}
const ModuleAState: ModuleA = {
name: 'fangfang',
hobby: ['看书'],
};
const getters = {
oath(state: ModuleA): string {
return ${state.name} love yueyue
;
},
};
const actions = {
addHobby({ commit }: { commit: any }, hobby: string) {
commit('ADD_HOBBY', hobby);
},
};
const mutations = {
ADD_HOBBY(state: ModuleA, hobby: string): void {
state.hobby = [...state.hobby, hobby];
},
};
export default {
namespaced: true,
state: ModuleAState,
getters,
actions,
mutations,
};
store.ts
import Vue from 'vue';
import Vuex from 'vuex';
import ModuleA from './modules/moduleA';
Vue.use(Vuex);
export default new Vuex.Store({
modules: {
ModuleA,
},
state: {
name: 'test',
},
});
`
xx.vue
`
`
xx.vue ,vuex type is missing. Do you have any good solutions?
You should manually annotate the mapped property types.
@Component
export default class Comp extends Vue {
@State
price!: number;
}