当前位置:网站首页>Atguigu---17-life cycle
Atguigu---17-life cycle
2022-06-25 09:04:00 【Zhangshao】
Life cycle introduction
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Lead to the life cycle </title>
<!-- introduce Vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- Life cycle : 1. also called : Life cycle callback function 、 Life cycle function 、 Lifecycle hook . 2. What is it? :Vue Some special named functions that help us call at the critical moment . 3. The name of the lifecycle function cannot be changed , But the specific content of the function is written by the programmer according to the requirements . 4. In the life cycle function this The point is vm or Component instance object . -->
<!-- Prepare a container -->
<div id="root">
<h2 v-if="a"> How do you do </h2>
<h2 :style="{opacity}"> Welcome to learn Vue</h2>
</div>
</body>
<script type="text/javascript"> Vue.config.productionTip = false // prevent vue Generate production prompts at startup . new Vue({
el:'#root', data:{
a:false, opacity:1 }, methods: {
}, //Vue Complete the parsing of the template and put the initial real DOM After the element is placed on the page ( The mount is finished ) call mounted mounted(){
console.log('mounted',this) setInterval(() => {
this.opacity -= 0.01 if(this.opacity <= 0) this.opacity = 1 },16) }, }) // Through the external timer ( Not recommended ) /* setInterval(() => { vm.opacity -= 0.01 if(vm.opacity <= 0) vm.opacity = 1 },16) */ </script>
</html>
Life cycle diagram

Analysis life cycle
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Analysis life cycle </title>
<!-- introduce Vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- Prepare a container -->
<div id="root" :x="n">
<h2 v-text="n"></h2>
<h2> Current n The value is :{
{n}}</h2>
<button @click="add"> Am I n+1</button>
<button @click="bye"> Point I destroy vm</button>
</div>
</body>
<script type="text/javascript"> Vue.config.productionTip = false // prevent vue Generate production prompts at startup . new Vue({
el:'#root', // template:` // <div> // <h2> Current n The value is :{
{n}}</h2> // <button @click="add"> Am I n+1</button> // </div> // `, data:{
n:1 }, methods: {
add(){
console.log('add') this.n++ }, bye(){
console.log('bye') this.$destroy() } }, watch:{
n(){
console.log('n Changed ') } }, beforeCreate() {
console.log('beforeCreate') }, created() {
console.log('created') }, beforeMount() {
console.log('beforeMount') }, mounted() {
console.log('mounted') }, beforeUpdate() {
console.log('beforeUpdate') }, updated() {
console.log('updated') }, beforeDestroy() {
console.log('beforeDestroy') }, destroyed() {
console.log('destroyed') }, }) </script>
</html>
Summary life cycle
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Lead to the life cycle </title>
<!-- introduce Vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- Common life cycle hooks : 1.mounted: send out ajax request 、 Start timer 、 Binding custom events 、 Subscribe to news, etc 【 Initialization operation 】. 2.beforeDestroy: Clear timer 、 Unbind custom events 、 Unsubscribe messages, etc 【 Finishing work 】. About destruction Vue example 1. Destroy with the help of Vue Developer tools don't see any information . 2. After destruction, the custom event will become invalid , But the original DOM The event is still valid . 3. Usually not in beforeDestroy Operational data , Because even if you manipulate data , The update process will no longer be triggered . -->
<!-- Prepare a container -->
<div id="root">
<h2 :style="{opacity}"> Welcome to learn Vue</h2>
<button @click="opacity = 1"> Transparency set to 1</button>
<button @click="stop"> Click me to stop the transformation </button>
</div>
</body>
<script type="text/javascript"> Vue.config.productionTip = false // prevent vue Generate production prompts at startup . new Vue({
el:'#root', data:{
opacity:1 }, methods: {
stop(){
this.$destroy() } }, //Vue Complete the parsing of the template and put the initial real DOM After the element is placed on the page ( The mount is finished ) call mounted mounted(){
console.log('mounted',this) this.timer = setInterval(() => {
console.log('setInterval') this.opacity -= 0.01 if(this.opacity <= 0) this.opacity = 1 },16) }, beforeDestroy() {
clearInterval(this.timer) console.log('vm I'm going to travel to the West ') }, }) </script>
</html>
边栏推荐
- 紧急行政中止令下达 Juul暂时可以继续在美国销售电子烟产品
- Unity--configurable joint -- a simple tutorial to get you started with configurable joints
- QSS buttons of different styles
- Summary of hardfault problem in RTOS multithreading
- matplotlib matplotlib中决策边界绘制函数plot_decision_boundary和plt.contourf函数详解
- Lvs-dr mode multi segment case
- 【OpenCV】—离散傅里叶变换
- Hyper-v:hyper-v generation 1 or generation 2 virtual machines
- 获取扫码的客户端是微信还是支付宝
- nodejs 使用Express框架demo
猜你喜欢

Le labyrinthe des huit diagrammes de la bataille de cazy Chang'an

(translation) the use of letter spacing to improve the readability of all capital text

sklearn PolynomialFeatures的具体用法

Lvs-dr mode multi segment case

Oracle-单行函数大全

Specific usage of sklearn polynomialfeatures

浅谈Mysql底层索引原理

The meshgrid() function in numpy

某视频网站m3u8非感知加密分析

Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed
随机推荐
声纹技术(三):声纹识别技术
Socket programming -- poll model
cazy長安戰役八卦迷宮
The meshgrid() function in numpy
Is it safe to open a stock account through the account opening QR code of the account manager? Or is it safe to open an account in a securities company?
sklearn PolynomialFeatures的具体用法
Make a skylearn high-dimensional dataset_ Circles and make_ moons
nodejs 使用Express框架demo
三、自动终止训练
声纹技术(四):声纹识别的工程部署
C#启动程序传递参数丢失双引号,如何解决?
socket编程——poll模型
WebGL谷歌提示内存不够(RuntimeError:memory access out of bounds,火狐提示索引超出界限(RuntimeError:index out of bounds)
Summary of hardfault problem in RTOS multithreading
《乔布斯传》英文原著重点词汇笔记(三)【 chapter one】
声纹技术(一):声纹技术的前世今生
In Section 5 of bramble pie project practice, Nokia 5110 LCD is used to display Hello World
C language: count the number of words in a paragraph
When unity released webgl, jsonconvert Serializeobject() conversion failed
声纹技术(五):声纹分割聚类技术