当前位置:网站首页>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't
To 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
边栏推荐
- 24岁秃头程序员教你微服务交付下如何持续集成交付,学不会砍我
- Etcd visualization tool: an introduction to kstone (I)
- 10: 00 interview, came out at 10:02, the question is really too
- What you have to know under the digital collection boom
- 今天睡眠质量记录80分
- [proteus simulation] L297 driving stepping motor
- 浅谈 SAP 软件里的价格折扣设计原理
- LDD 知识整理
- 一次简单的反射型XSS操作及思路
- ID卡复制教程(使用T5577卡复制4100卡)
猜你喜欢
Tiktok actual battle ~ list of bloggers I follow, follow and check
Use open connector to integrate hubspot and SAP systems
Traffic management and control of firewall Foundation
What is the maximum number of concurrent TCP connections for a server? 65535?
Among US private server setup
Geoffrey Hinton:我的五十年深度学习生涯与研究心法
今天睡眠质量记录80分
Introduction to reverse commissioning PE structure details 02/07
Azure Kinect微软摄像头Unity开发小结
among us私服搭建
随机推荐
MySQL self connection query "suggestions collection"
QT interface library
How to query all the data in a table in the database?
【Hot100】3. Longest substring without duplicate characters
北京有哪些牛逼的中小型公司?
Slim GAIN(SGAIN)介绍及代码实现——基于生成对抗网络的缺失数据填补
全球陆续拥抱Web3.0,多国已明确开始抢占先机
抖音实战~我关注的博主列表、关注、取关
使用Karmada实现Helm应用的跨集群部署
A little hesitant in the morning
PID控制详解[通俗易懂]
【Hot100】2.两数相加
Redmibook Pro 14 enhanced version cannot open delta software drastudio_ v1.00.07.52
WPF 视频硬解码渲染播放(无空域)(支持4K、8K、高帧率视频)
[recommendation system] esmm model of multi task learning (updating)
Why MySQL table connection is faster than subquery
岛屿类问题通用解法与DFS框架
tablestore中可以使用sql查询可以查出表中所有的数据吗?
Navicat 15 for MySQL
如何查询数据库中一个表中的所有数据呢?