当前位置:网站首页>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 !
边栏推荐
- Pytoch foundation - (2) mathematical operation of tensor
- MySQL reads missing data from a table in a continuous period of time
- RT thread -- FTP of LwIP (2)
- [PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos
- [meisai] meisai thesis reference template
- Mathematical modeling regression analysis relationship between variables
- Simple blog system
- Cf464e the classic problem [shortest path, chairman tree]
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
猜你喜欢

2. GPIO related operations

Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control

【可调延时网络】基于FPGA的可调延时网络系统verilog开发

Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)

C (XXIX) C listbox CheckedListBox Imagelist

How to modify field constraints (type, default, null, etc.) in a table

Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did

WPF效果第一百九十一篇之框选ListBox

C (thirty) C combobox listview TreeView

Proof of Stirling formula
随机推荐
UDP reliable transport protocol (quic)
A brief introduction to symbols and link libraries in C language
mysql从一个连续时间段的表中读取缺少数据
In Net 6 CS more concise method
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
Cf464e the classic problem [shortest path, chairman tree]
KS003基于JSP和Servlet实现的商城系统
Conditionally [jsonignore]
Maxay paper latex template description
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos
Flask learning and project practice 9: WTF form verification
Why do you want to start pointer compression?
DM8 archive log file manual switching
Detailed explanation of serialization and deserialization
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
阿里测试师用UI自动化测试实现元素定位
Multi project programming minimalist use case
LTE CSFB test analysis
[practice] mathematics in lottery
Determine which week of the month the day is