created()中にフェッチしたdbオブジェクトを反復しようとしていますが、console.logでは値を取得しますが、v-forテンプレートの部分は空のままです。私の副次的な質問は:この良い習慣は?私はVueの新機能です。この問題に関する私の検索では、それがライフサイクルの問題だと思っています。動的アイテムのv-forでの反復
ありがとうございました。
TEMPLATEのPART:
.content(v-for="(content, key, index) in contents")
h3 {{key}}
.line
| {{getValue(content)}} // this is blank
方法PART:
getValue(value) {
PagesService.fetchDataWrap({
id: value
}).then((response) => {
const test = response.data.values[0].value
console.log(test) //this is working and gives the right value
return test
})
},
getPage() {
PagesService.fetchPage({
id: this.$route.params.page
}).then((response) => {
this.name = response.data.result.name
this.langs = response.data.result.langs
this.project = response.data.result.parent
this.contents = response.data.result.values
})
this.getProject()
}
にconsole.log(this.contents)結果:私は時に送信する値である
{__ob__: Observer}
footer: "5a29943b719236225dce6191"
header: "5a29a9f080568b2484b31ee1"
v - 内容を反復するためにgetValueが処理して対応する値を取得できる
/どこをレンダリングするためにロードされていることを信頼することができますあなたは 'getPage()'を呼び出しますか?あなたが 'async' /' await'を使う理由が見えません。あなたのメソッドは何も返さず、非同期操作を使って完了しません。 – Phil
'getPage()'がコンポーネントの 'created()'部分で呼び出された場合、メソッドは正しい値を返します。 – Sunkhern
いいえ、そうではありません。実際には、彼らは何も返さない – Phil