手把手教你VUE从入门到放弃—— 篇六(vue实例的生命周期,八个常用生命周期钩子函数)

详情可见官网链接

vue实例的生命周期

 生命周期函数:vue实例在某个时间点会自动执行的函数

八个常用生命周期函数:

beforecreate与created: 实例创建前与创建后执行

beforemount与mounted:数据与html模板结合渲染到页面之前与之后执行

beforedestroy与destroyed:实例销毁前与之后执行

beforeupdate与updated:实例内的数据修改前与之后执行

源码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue实例的生命周期</title>
      <script src="vue.js"></script>
</head>
<body>
    <div id = 'app2'>
        <input type='text' v-model='inputVal'/>
    </div>
    <script>
        var app = new Vue({
            el:'#app2',
            data:{
                list:[],
                inputVal : 'zzz'
             },
             beforeCreate:function(){
                 console.log("beforeCreate");
             },
             created:function(){
                 console.log("created");
             },
             beforeMount:function(){
                             console.log("beforeMount"); 
             },
             mounted:function(){
                             console.log("mounted"); 
             },
             beforeDestroy:function(){
                             console.log("beforeDestroy"); 
             },
             destroyed:function(){
                console.log("destroyed"); 
             },
             beforeUpdate:function(){
                             console.log("beforeUpdate"); 
             },
             updated:function(){
                             console.log("updated"); 
             }
        });
    </script>
</body>


</html>

演示如下,可在控制台执行destroy 与修改对象里的属性值来触发 beforedestroy与destroyed,beforeupdate与updated

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我才是真的封不觉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值