VUE中钩子生命周期
一个vue会有8个钩子,data和methods不算,生命周期需要的数据和函数
mounted是组件都加载完成后做事情(例如添加定时器)
一个组件页面可以正常进行,就已经跑完前4个钩子了
页面数据发生变化等就会执行beforeUpdate,Updata
第7 8 个组件调用$destroy()来执行删除(这样销毁不会销毁全局的东西,定义在全局的定时器等要注意)
clearInterval(this.intervalId);
beforeCreate() {
console.log("1.beforeCreate");
},
data(){
return{
}
},
methods:{
},
created() {
console.log("2.created");
},
beforeMount() {
console.log("3.beforeMount");
},
mounted() {
console.log("4.mounted");
},
beforeUpdate() {
console.log("5.beforeUpdate");
},
updated() {
console.log("6.updated");
},
beforeDestroy() {
console.log("7.beforeDestroy");
},
destroyed() {
console.log("8.destroyed");
}