我面临一个问题,在更新我的储值isRenewalFlow
之后,我的组件没有得到更新。
在调试时,我发现在突变updated
更新了存储值之后,没有调用组件的[MUTATION_TYPES.IS_RENEWAL_FLOW]
生命周期。甚至在商店吸气剂中的getIsRenewalFlow
在开始时仅被调用一次,而在突变内部商店更新之后则不会被调用。
这是代码。
商店
const state = {
isRenewalFlow: undefined,
}
const getters = {
getIsRenewalFlow: (state) => state.isRenewalFlow,
}
const actions = {
[ACTION_TYPES.POPULATE_QUOTE_DATA]: (
{ dispatch, commit, state, rootState, getters }, payload
) => {
commit(MUTATION_TYPES.IS_RENEWAL_FLOW, payload)
}
}
const mutations = {
[MUTATION_TYPES.IS_RENEWAL_FLOW]: (state, payload) => {
state.isRenewalFlow = payload
},
}
组件
export default Vue.extend({
components: {
ErrorBoundary: () => import('@/components/common/ErrorBoundary.vue'),
},
computed: {
...mapGetters({
getIsRenewalFlow: 'getIsRenewalFlow',
}),
},
mounted() {
this.getIsRenewalFlow !== undefined &&
someFunc()
},
updated() {
this.getIsRenewalFlow !== undefined &&
someFunc()
},
})
someFunc
从未被调用,即使在state.isRenewalFlow
true
内用false
或mutations
更新了[MUTATION_TYPES.IS_RENEWAL_FLOW]
答案 0 :(得分:1)
updated
挂钩与DOM中的更改有关,如果此状态未更新DOM,则不会看到updated
被调用。
来自https://vuejs.org/v2/guide/instance.html#Lifecycle-Diagram: