watch
prop
(在你的情况下
item
的
id
):
watch: {
'item.id': {
handler(id) {
if (id) {
// call API, using the id
}
},
immediate: true /* makes it run immediately after you set the watcher,
* does not wait until first change (like `created` call) */
}
}
null
当子组件关闭时通知子数据,这样当您第二次打开它时,它不会在新的API调用获取时显示旧数据。
作为旁注,
v-if="Object.keys(selectedItem).length > 0"
可以简化为
v-if="selectedItem.id"