当前位置:网站首页>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
边栏推荐
- 【Hot100】1. Sum of two numbers
- 请问下大家有遇到过这种设置的主健和数据库一致的错误吗?
- #夏日挑战赛#OHOS构建自定义服务实战
- among us私服搭建
- A simple reflective XSS operation and idea
- 你好,现在网上炒股开户买股票安全吗?
- WPF 视频硬解码渲染播放(无空域)(支持4K、8K、高帧率视频)
- Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
- AI落地的新范式,就“藏”在下一场软件基础设施的重大升级里
- Redmibook Pro 14 enhanced version cannot open delta software drastudio_ v1.00.07.52
猜你喜欢

Geoffrey Hinton:我的五十年深度学习生涯与研究心法

Briefly introduce the conversion between tensorflow and pytorch (mainly tensorflow to pytorch)

The sadness of software testers is Their own technical ability can not meet the requirements of large manufacturers?

The world has embraced Web3.0 one after another, and many countries have clearly begun to seize the initiative

Etcd可视化工具:Kstone简介(一)

QQ出现大规模盗号,为什么会这样?就没有解决方法了吗?

岛屿类问题通用解法与DFS框架

A 24-year-old bald programmer teaches you how to continuously integrate and deliver microservice delivery. You can't learn how to cut me off

榜单首发——线控制动「新周期」,本土供应商市场竞争力TOP10

【Proteus仿真】L297驱动步进电机
随机推荐
LDD 知识整理
Can SQL queries be used in the tablestore to find out all the data in the table?
Super automation and the future of network security
Slim gain (sgain) introduction and code implementation -- missing data filling based on generated countermeasure network
ID卡复制教程(使用T5577卡复制4100卡)
Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
Yesterday, yuancosmos | meta's "yuancosmos" Department lost $2.96 billion in the first quarter, and Liufu jewelry issued Digital Collections
北京有哪些牛逼的中小型公司?
使用 Open Connector 进行 HubSpot 和 SAP 系统的集成工作
Operating excel with openpyxl
MySQL auto - Connect Query recommended favorites
【Hot100】3. 无重复字符的最长子串
5分钟的时间制作一个反弹球游戏
What is the maximum number of concurrent TCP connections for a server? 65535?
【Hot100】4. Find the median of two positive arrays
【Hot100】1. Sum of two numbers
运维-- 统一网关非常必要
QQ出现大规模盗号,为什么会这样?就没有解决方法了吗?
What you have to know under the digital collection boom
GAIN的代码实现(4)——基于GAN的Spam数据集缺失数据填补(序)【改进版】