1.Vue的生命周期

1.1 代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>声明周期函数</title>
</head>

<body>
    <div id="app">
        <div id="out">{{title}}</div>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        var vm=new Vue({
           el:'#app',
           data:{
               title: "web前端开发"
           },
           methods:{

           },
           //声明周期钩子
           created(){
               //一般在这里去请求网络
               console.log("created");
               var out = document.getElementById("out");
               console.log(out);
           },
           mounted(){
               console.log("mounted");
               var out = document.getElementById("out");
               console.log(out);
           }
        });
    </script>
</body>

</html>

1.2 显示效果

最后修改:2021 年 02 月 22 日 01 : 40 PM