數(shù)據(jù)是這樣的{
"id" : 1,
"name" : "testName",
"info" : {
"face" : "xxxxxxx,jpg"
"mobile" : "xxxxxx"
}
}在模板中{{user.info.mobile}} //這樣就報錯undefined只能寫成{{user.info ? user.info.face: ''}}
{{user.info ? user.info.mobile : ''}} //這樣就沒毛病了這樣寫好麻煩啊 有其他辦法嗎?
2 回答

12345678_0001
TA貢獻1802條經(jīng)驗 獲得超5個贊
出現(xiàn)這個原因,是因為請求是異步的吧
要么,數(shù)據(jù)初始化,data的
return{ { "id" : "", "name" : "", "info" : { "face" : "" "mobile" : "" } } }
里面定義個初始化內(nèi)容,要么在template模版里面 v-if,數(shù)據(jù)拿到再渲染
第一種會閃一下空,然后數(shù)據(jù)再渲染,第二種是完全等數(shù)據(jù)下來再渲染
添加回答
舉報
0/150
提交
取消