【发布时间】:2020-11-03 23:23:11
【问题描述】:
我花了很多时间弄清楚如何使用vuex map helper函数,最后还是没有弄明白。
现在我有这样的东西:
setup (_, { root: { $store } }) {
onMounted(() => {
$store.commit('app/setApplicationWidth', innerWidth)
console.log($store.getters['app/getApplicationWidth'])
})
}
那么我如何在组合 API 中使用 mapGetters 和 mapMutations?
我的 vuex 商店是这样的: /store/app.ts
import { GetterTree, MutationTree, ActionTree } from 'vuex'
export const state = () => ({
appWidth: <Number> 0
})
export type RootState = ReturnType<typeof state>
export const mutations: MutationTree<RootState> = {
setApplicationWidth (state: any, payload: Number) {
state.appWidth = payload
}
}
export const getters: GetterTree<RootState, RootState> = {
getApplicationWidth (state: any): Number {
return state.appWidth
}
}
export const actions: ActionTree<RootState, RootState> = {}
【问题讨论】:
标签: nuxt.js vuex vue-composition-api