1 回答

TA貢獻1798條經驗 獲得超3個贊
通常,您會使用 vuex 之類的東西將此模型邏輯分離到自己的模塊中,因此組件的數據流是完全單向的。
但在這種情況下,最簡單的解決方案是在 App.vuev-if="responseReady"中向組件添加指令,<Weather>以便在數據準備好之前它不會被掛載。您還需要為這個新道具添加一個布爾標志到dataand onResponse。同樣,這是快速而骯臟的解決方案。
<Weather v-if="responseReady" msg="The weather for:" :lat="lat" :long="long" :ip="ip" :city="city" :country="country"/>
...
data() {
return {
lat: 0,
long: 0,
ip: 0,
country: 0,
city: 0,
responseReady: false
}
},
...
onResponse(event) {
this.lat = event.lat
this.long = event.long
this.ip = event.ip
this.country = event.country
this.city = event.city
this.responseReady = true;
}
添加回答
舉報