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;
}
添加回答
举报