当前位置:网站首页>Solve the problem that subcomponents will not be destroyed through setTimeout
Solve the problem that subcomponents will not be destroyed through setTimeout
2022-06-28 16:24:00 【Attacking-Coder】
Project description
Code parameter description
this.preview=true/false To control whether the sub components are rendered
this.previewUrl To control the rendering of the newly rendered images in the self-assembly url
private handleItemPreviewClick(url) {
this.showPreview = false;
setTimeout(() => {
this.previewUrl = url;
this.showPreview = true;
}, 0);
}
// Lifecycle functions for subcomponents
public destroyed(): void {
console.log(' The destruction ');
}
At this point, when we trigger the parent component handleItemPreviewClick Function, the sub components will be destroyed
This is because : When we're done this.showPreview = false; setTimeout The code in will be placed in the macro task queue , The code in the page will not be executed until the page is re rendered
Error code cases
private handleItemPreviewClick(url) {
this.showPreview = false;
this.previewUrl = url;
this.showPreview = true;
}
// Lifecycle functions for subcomponents
public destroyed(): void {
console.log(' The destruction ');
}
At this point, when we trigger the parent component handleItemPreviewClick Function time subcomponent
Can'tTo destroy
This is because : When we're done this.showPreview = false; Immediately afterwards, it was carried out again this.showPreview = true;, When the code is finished Browser discovery showPreview The value of has not changed , The subcomponents will not be destroyed
边栏推荐
猜你喜欢

Introduction to reverse commissioning PE structure details 02/07

Today's sleep quality record is 80 points

among us私服搭建

【初学者必看】vlc实现的rtsp服务器及转储H264文件

3. caller service call - dapr

Internet of things cloud convergence Security Guide

Focus on the 35 year old Kan: fear is because you don't have the ability to match your age

10 years of testing experience, worthless in the face of the physiological age of 35

Visual studio 2019 software installation package and installation tutorial

【Hot100】1. 两数之和
随机推荐
Mysql自连接查询「建议收藏」
Code implementation of gain (4) -- gap dataset missing data filling based on GaN (sequence) [improved version]
Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills
开源技术交流丨一站式全自动化运维管家ChengYing入门介绍
Big God explains open source buff gain strategy live lecture
[high concurrency foundation] MySQL index optimization
【Hot100】1. Sum of two numbers
Knowing these commands allows you to master shell's own tools
What are the most powerful small and medium-sized companies in Beijing?
#夏日挑战赛#OHOS构建自定义服务实战
【推荐系统】多任务学习之ESMM模型(更新ing)
Zuckerberg to investors: don't expect anything from metauniverse
如何根据多元索引查询最后一条数据,达到 sql order by desc limit 1的效果呢?
北京有哪些牛逼的中小型公司?
tablestore中可以使用sql查询可以查出表中所有的数据吗?
3. Caller 服务调用 - dapr
QQ出现大规模盗号,为什么会这样?就没有解决方法了吗?
简单介绍一下tensorflow与pytorch的相互转换(主要是tensorflow转pytorch)
防火墙基础之流量管理与控制
Deep learning convolutional neural network of machine learning to realize handwritten font recognition based on CNN network