[英]Detect a proxy change vuejs3
I don't know how to detect a proxy object change without display it.我不知道如何检测代理 object 更改而不显示它。
I Use async API call to set a proxy object (from a parent component).我使用异步 API 调用来设置代理 object(来自父组件)。
In my child component, I use it like this在我的子组件中,我这样使用它
computed: {
user() { return dataProxy.getCurrentUser() // return a proxy object }
}
updated: {
console.debug(this.user)
if(this.user.id !== undefined) {
loadUserDetails(this.user)
}
}
When the component is mounted, updated
method is called and the console display an empty proxy object (ok) But when the proxy object is updated from api response, the updated
method is never called.当组件被挂载时, updated
方法被调用并且控制台显示一个空代理 object (ok) 但是当代理 object 从 api 响应更新时, updated
方法永远不会被调用。
Now, If I add {{user}}
on my template, the updated
method is called after the API response with the right content.现在,如果我在我的模板上添加{{user}}
, updated
后的方法将在包含正确内容的 API 响应后调用。
how to detect a proxy object change without display it?如何检测一个代理object变化而不显示呢?
You should use a watch
function:您应该使用watch
function:
watch: {
user(newUser) {
console.log('user changed:', newUser);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.