Vue的生命周期

生命周期:
1.又名:生命周期回调函数、生命周期函数、生命周期钩子。
2.是什么:Vue在关键时刻帮我们调用的些特殊名称的函数。
3.生命周期函数的名字不可更改,但函数的具体内容是程序员根据需求编写的。
4.生命周期函数中的this指向是vm或组件实例对象。
示例:
<div id="root">
<h2 :style="{opacity}">欢迎学习Vue</h2>
<h2 v-if="a">欢迎学习Vue</h2>
</div>
<script>
new Vue({
el:'#root',
data:{
a:false,
opacity: 1
},
methods:{
},
mounted(){
setInterval(()=>{
this.opacity -=0.01
if (this.opacity<=0) this.opacity= 1
},16)
}
})
</script>

浙公网安备 33010602011771号