我想訪問異步 fetch() 中的道具,但我也在使用異步 fetch(context)。所以,我不確定如何訪問道具。
uj5u.com熱心網友回復:
在 Nuxt 2 中,您有 2 個fetch鉤子。
舊的,在 Nuxt 2.12 之前,fetch(context)它的行為很像asyncData. 它在組件創建之前執行,因此您無權訪問它(資料、道具、選項......什么都沒有)。
這個已棄用,請asyncData改用。
來自 Nuxt 2.12 的新版本fetch()(沒有引數)。created()它與鉤子同時執行。它可以訪問組件的背景關系(道具、資料等)。
fetch(context) {
// "this" doesn't exists
// context is the Vue global context
}
fetch() {
this.myProp // "this" exists and have access to props
}
uj5u.com熱心網友回復:
如檔案this中所示,您可以在使用fetch()鉤子時訪問背景關系,例如
async fetch() {
await this.$axios // or whatever this.$i18n etc.....
}
不要像這里fetch(context)解釋的那樣使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/466592.html
