赞
踩
<!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>Document</title> <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> </head> <body> <div id="root"> <school /> </div> <script> // 子组件 const student = Vue.extend({ name: 'student', template: ` <div>子组件</div> `, data() { return {}; }, beforeCreate() { console.log("子组件————beforeCreate..."); }, created() { console.log("子组件————create..."); }, beforeMount() { console.log("子组件————beforeMount..."); }, mounted() { console.log("子组件————mounted..."); }, beforeUpdate() { console.log("子组件————beforeUpdate..."); }, updated() { console.log("子组件————updated..."); }, beforeDestroy() { console.log("子组件————beforeDestroy..."); }, destroyed() { console.log("子组件————destroyed..."); } }) // 父组件 const school = Vue.extend({ name: 'school', template: ` <div> {{text}} <button @click="handle">点击销毁</button> <student/> </div> `, components: { student }, data() { return { text: "哈哈", }; }, methods: { handle() { this.$destroy(); }, }, beforeCreate() { console.log("父组件————beforeCreate..."); }, created() { console.log("父组件————create..."); }, beforeMount() { console.log("父组件————beforeMount..."); }, mounted() { console.log("父组件————mounted..."); }, beforeUpdate() { console.log("父组件————beforeUpdate..."); }, updated() { console.log("父组件————updated..."); }, beforeDestroy() { console.log("父组件————beforeDestroy..."); }, destroyed() { console.log("父组件————destroyed..."); }, }) const vm = new Vue({ name: 'vm', el: '#root', components: { school } }) </script> </body> </html>
https://www.jb51.net/article/145474.htm
react 生命周期指的是组件从创建到卸载的整个过程,每个过程都有对应的钩子函数会被调用,它主要有以下几个阶段:
Vue开发遇到的问题,刚好先给React踩个坑了,总之得埋上
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。