vue-组件生命周期

生命周期各个阶段

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Examples</title>
</head>
<body>
    <div id="box">
        <ul>
            <li v-for="data in datalist" :key="data.filmId">
                <h3>{{data.name}}</h3>
                <img :src="data.poster" />
            </li>
        </ul>
        <child v-if="isCreated"></child>
    </div>

    <script src="http://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script type="text/javascript">
        Vue.component("child", {
            template: `<div id="aaa">
             child --{{title}}
            <button @click="title='1111111'">change1</button>
            <button @click="title='2222222'">change2</button>
        </div>`,
            data() {
                return {
                    title: "00000",
                    datalist: [],
                    count: 0
                }
            },

            methods: {
            },

            beforeCreate() {
                console.log("beforeCreate")
            },
            created() {
                console.log("created")
            },

            beforeMount() {
                console.log("beforeMount")
            },

            mounted() {
                console.log("mounted", "访问dom,setInterval,window.onscroll, 监听事件 ajax")
            },

            beforeUpdate() {
                console.log("beforeUpdate")
            },

            updated() {
                console.log("updated", "更新之后可以访问dom")
            },

            beforeDestroy() {
                console.log("beforeDestroy-clearInterval ,window.οnscrοll=null,$off");
            },

            destroyed() {
                console.log("destroyed--clearInterval ,window.οnscrοll=null,$off")
            }
        })
        var vm = new Vue({
            el: "#box",
            data: {
                isCreated: true,
                datalist: []
            },
        })
    </script>
</body>
</html>
vm.isCreated
true
vm.isCreated=false
组件生命周期.html:61 beforeDestroy-clearInterval ,window.onscroll=null,$off
组件生命周期.html:65 destroyed--clearInterval ,window.onscroll=null,$off
false
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值