【问题标题】:Load page title from store in Nuxt.js从 Nuxt.js 中的商店加载页面标题
【发布时间】:2020-05-05 04:09:08
【问题描述】:

我正在尝试加载商店后的页面标题。但是,我不确定如何正确执行。这就是我理解应该这样做的方式,但它不起作用。它表示该对象尚未加载(无法读取未定义的属性“p_pdf_ad_headlines”)。

我将如何在 Nuxt 中做到这一点?

async fetch({ store, params }) {
    await store.dispatch('getMixedLanding', { id: params.id })
},
head() {
    return {
        title: this.$store.state.landing.p_pdf_ad_headlines.page_headline
            .text
    }
}

【问题讨论】:

    标签: javascript vue.js nuxt.js


    【解决方案1】:

    我想通了。对于其他人来说,我唯一做的就是将dispatch 函数放入fetch 函数中。 head 保持不变。

    
        async fetch({ store, params }) {
            const response = await axios.get(
                'http://example.com/item/' + params.id + '/'
            )
            store.commit('mixedResponse', response)
        },
    
    
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-14
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 1970-01-01
      相关资源
      最近更新 更多