当前位置:网站首页>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>
边栏推荐
- 华泰证券在上面开股票账户安全吗?
- How to solve the 10061 error of MySQL in Linux
- 《乔布斯传》英文原著重点词汇笔记(二)【 chapter one】
- 【MYSQL】索引的理解和使用
- 云网络技术的好处以及类型
- Summary of hardfault problem in RTOS multithreading
- 声纹技术(五):声纹分割聚类技术
- Flitter gets the height of the top status bar
- When unity released webgl, jsonconvert Serializeobject() conversion failed
- (翻译)采用字母间距提高全大写文本可读性的方式
猜你喜欢

How to increase the monthly salary of software testing from 10K to 30K? Only automated testing can do it

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

5、 Project practice --- identifying man and horse

微服务调用组件Ribbon底层调用流程分析

城鏈科技平臺,正在實現真正意義上的價值互聯網重構!

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

【OpenCV】—输入输出XML和YAML文件

C language: count the number of words in a paragraph

JMeter interface test, associated interface implementation steps (token)

2、 Training fashion_ MNIST dataset
随机推荐
声纹技术(一):声纹技术的前世今生
Unknown table 'column of MySQL_ STATISTICS‘ in information_ schema (1109)
How to design test cases
Socket programming -- epoll model
LVS-DR模式单网段案例
3、 Automatically terminate training
微服务调用组件Ribbon底层调用流程分析
The meshgrid() function in numpy
【无标题】**数据库课设:三天完成学生信息管理系统**
《乔布斯传》英文原著重点词汇笔记(二)【 chapter one】
3 big questions! Redis cache exceptions and handling scheme summary
WebGL发布之后不可以输入中文解决方案
Openfoam: bottom layer
自定义注解之编译时注解(RetentionPolicy.CLASS)
在华泰证券上面开户好不好,安不安全?
Fault: 0x800ccc1a error when outlook sends and receives mail
C program termination problem clr20r3 solution
City Chain technology platform, really Realizing value Internet reconstruction!
十大券商开户风险大吗,安全靠谱吗?
The first techo day Tencent technology open day, 628 waiting for you!