【问题标题】:VueStoreFront: Custom module: state is updated, component notVueStoreFront:自定义模块:状态已更新,组件未更新
【发布时间】:2019-07-14 07:24:20
【问题描述】:

我正在创建一个自定义模块,它在“afterRegistration”挂钩中获取数据并将结果保存到存储中。

状态已更新(可以在VueDevTools中看到更新),但组件仍然有默认状态。我做错了什么?

// afterRegistration
export function afterRegistration ({Vue, config, store, isServer}) {
  store.dispatch(${KEY}/isVisible)
}

// component
export default {
  name: 'Test',
  components: { Fragment },
  props: {
   …
  },
  computed: {
    isVisible: el => el.$store.getters['myModule/simpleTest']
  }
}

【问题讨论】:

  • computed对象中,使用mapState,你必须声明你需要在你的组件中使用的状态变量

标签: vue.js vuex vue-storefront


【解决方案1】:

你已经失去了反应。将状态对象中simpleTest 的初始值设置为您喜欢的任何值(从上下文中我看到它是Boolean)。如果该字段未处于初始状态,则该字段没有 getter 或 setter。

【讨论】:

    【解决方案2】:

    好的,我发现我需要在 AsyncLoader 中调度

    // afterRegistration
    export function afterRegistration ({Vue, config, store, isServer}) {
      AsyncDataLoader.push({
       execute: ({ route, store, context }) => {
        return new Promise ((resolve, reject) => {
          store.dispatch(`${KEY}/getInlineTranslationConfig`)
            .then(() => resolve(null))
        })
      }
    })
    

    现在可以了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-25
      • 2019-08-31
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-15
      相关资源
      最近更新 更多