当前位置:网站首页>Yyds dry goods inventory web components series (VII) -- life cycle of custom components
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
2022-07-06 03:57:00 【Programming samadhi】

Preface
What is meant by ” Life cycle “? seeing the name of a thing one thinks of its function , The life cycle refers to the whole process of an object from its birth to its death , Of course , The specific stage division of the life cycle of different objects may be different .
When we use the front-end component framework , We all know that each component has its own life cycle , After defining the component life cycle , Developers can execute different code logic in different life cycles of components , So as to achieve the role of management components .
In order to make Custom Elements More flexible in use , It also has the ” Life cycle “ Callback function , It allows developers to define methods that can be executed at different stages of the component's life .
Custom Elements Life cycle division
stay Custom Elements In the constructor of , You can specify multiple different callback functions , They will be called at different times of the element's life :
connectedCallback: When Custom Elements First inserted into document DOM when , Called .disconnectedCallback: When Custom Elements From the document DOM When deleted in , Called .adoptedCallback: When Custom Elements When moved to a new document , Called .attributeChangedCallback: When Custom Elements increase 、 Delete 、 When modifying its properties , Called .
Be careful : The lifecycle callback function of a custom element is used in its constructor .
Use of lifecycle callback function
First look at the effect :

What needs to be noted here is :adoptedCallback The callback is only available when the custom element is moved to a new document ( It's usually iframe) It will be triggered only when it is in .
The code is as follows :
Conclusion
That's all Custom Elements A simple example of using the lifecycle callback function , I hope it helped you !
Custom Elements In the callback function of ,adoptedCallback There are few usage scenarios , This needs attention .
- ~
- The end of this paper , Thank you for reading !
~
Learn interesting knowledge , Make interesting friends , Create interesting souls !
Hello everyone , I am a 〖 The samadhi of programming 〗 The author of Hermit King , My official account is 『 The samadhi of programming 』, Welcome to your attention , I hope you can give me more advice !
边栏推荐
- Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
- Schnuka: what is visual positioning system and how to position it
- Viewing and verifying backup sets using dmrman
- 【FPGA教程案例11】基于vivado核的除法器设计与实现
- BUAA calculator (expression calculation - expression tree implementation)
- 阿里测试师用UI自动化测试实现元素定位
- Python book learning notes - Chapter 09 section 01 create and use classes
- Codeforces Global Round 19
- [analysis of variance] single factor analysis and multi factor analysis
- How can programmers resist the "three poisons" of "greed, anger and ignorance"?
猜你喜欢

C (thirty) C combobox listview TreeView

SSTI template injection explanation and real problem practice

在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒

Ks008 SSM based press release system

Simple blog system

Alibaba testers use UI automated testing to achieve element positioning

3.1 detailed explanation of rtthread serial port device (V1)

Cubemx transplantation punctual atom LCD display routine

C#(二十八)之C#鼠标事件、键盘事件
![[practice] mathematics in lottery](/img/29/2ef2b545d92451cf083ee16e09ffb4.jpg)
[practice] mathematics in lottery
随机推荐
C language -- structs, unions, enumerations, and custom types
Use js to complete an LRU cache
Introduction to data types in MySQL
在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
Proof of Stirling formula
How to standardize the deployment of automated testing?
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
Record the pit of NETCORE's memory surge
Mapping between QoE and KQI
Align items and align content in flex layout
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
Failure causes and optimization methods of LTE CSFB
Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
阿里测试师用UI自动化测试实现元素定位
C form application of C (27)
Conditionally [jsonignore]
[practice] mathematics in lottery