首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Vue的生命周期函数

Vue的生命周期函数

作者头像
GeekLiHua
发布2025-01-21 13:12:49
发布2025-01-21 13:12:49
1950
举报
文章被收录于专栏:JavaJava

简介:Vue实例从创建到销毁是有一个生命周期的,在Vue中这个生命周期分成了多个阶段。 为了让程序员能够在合适的阶段做一些事情,比如对于一个商品页面,当用户看到页面时, 页面的商品都已经显示出来了。这意味着在页面显示出这些商品前,必须在生命周期的某个 阶段将数据从后端服务器读取过来。Vue2提供了8个生命周期钩子函数来供程序员使用:beforeCreate()created()beforeMount()mouted()beforeUpdate()updated()beforeDestory(), destroyed()

学习代码

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ref</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        
    </div>
</body>
<script>
    const app = new Vue({
        el:"#app",
     
        beforeCreate(){
            console.log("beforeCreate");
        },
        created(){
            console.log("created");
        },
        beforeMount(){
            console.log("beforeMount");
        },
        mounted(){
            console.log("mounted");
        },
        beforeUpdate(){
            console.log("beforeUpdate");
        },
        updated(){
            console.log("updated");
        },
        beforeDestory(){
            console.log("beforeDestory");
        },
        destoryed(){
            console.log("destroyed");
        },
        
    });
    </script>
</html>

运行结果

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档