根据Vue的生命周期说出console打印出来的值
export default {
data() {
num1: 1,
num2: 2,
},
computed: {
sum() {
return this.num1 + this.num2;
}
},
beforeCreate() {
console.log("beforeCreated", this.sum);
},
created() {
console.log("created", this.sum);
},
beforeMount() {
console.log("beforeMount", this.sum);
},
mounted() {
console.log("mounted", this.sum);
},
beforeUpdate() {
console.log("beforeUpdate", this.sum);
},
updated() {
console.log("updated", this.sum);
},
beforeDestroy() {
console.log("beforeDestroy", this.sum);
},
destroyed() {
console.log("destroyed", this.sum);
}
}
拓展
- 父子组件生命周期如何执行
- 父beforeCreate -> 父created -> 父beforeMount ->
- 子beforeCreate -> 子created -> 子beforeMount -> 子mounted ->
- 父mounted ->
- 父beforeUpdate -> 子beforeUpdate -> 子updated -> 父updated ->
- 父beforeDestroy-> 子beforeDestroy -> 子destroyed -> 父destroyed