我的 vue js 網(wǎng)站上的數(shù)據(jù)正在渲染,但我在控制臺中收到未定義的錯誤。我正在 App.vue 中進行 axios 調(diào)用,以從我的 cms 獲取數(shù)據(jù):應(yīng)用程序.vueasync created() {const strapiData = await getStrapiData();// Update Vuexthis.$store.dispatch('setStrapi', strapiData);}然后在我的組件之一中,我調(diào)用 getter 來檢索存儲在 vuex 中的數(shù)據(jù):關(guān)于.vuecomputed: { aboutData() { return this.$store.getters.strapiData.data.about }}然后我在模板代碼中引用它:<img :src="aboutData.photo.name">一切都渲染得很好,但這是我在網(wǎng)絡(luò)控制臺中看到的錯誤:TypeError: Cannot read property 'photo' of undefinedat a.r (About.vue?3e5e:1)我認(rèn)為這個問題與我的組件的創(chuàng)建順序有關(guān)。我將所有子組件導(dǎo)入到 App.vue 中并在那里渲染它們,但我認(rèn)為子組件是在 app.vue 創(chuàng)建的生命周期掛鉤之前創(chuàng)建的:應(yīng)用程序.vue腳本components: {'app-about' : About,App.vue模板<template> <div id="app"> <app-about></app-about> </div></template>有人知道我缺少什么嗎?謝謝你!
Vuex - 在計算中使用 getter 時出現(xiàn)未定義的錯誤
ibeautiful
2023-07-06 14:48:51