第一个组件
<template>
<view id="myView">
我是test组件
</view>
</template>
<script>
export default {
data() {
return {
num:3,
intId: null
}
},
beforeCreate() {
console.log("实例化已经开始初始化了")
// 用于销毁用下面 生周期
console.log(this.num);
},
created() { // 一般用在初始化数据
console.log("created",this.num)
// 用于销毁用下面生周期
this.intId = setTimeout(() => {
console.log("执行定时器");
},1000)
},
beforeMount() {
console.log("beforemount",document.getElementById("myView"))
},
mounted() { // 一般用操作DOM
console.log("mounted",document.getElementById("myView"))
},
destroyed() {
console.log("组件销毁了")
// 用于销毁用下面生周期
clearInterval(this.intId);
}
// methods: {
// }
}
</script>
<style>
</style>
第二个组件和第一个配合使用销毁查看