<!DOCTYPE html>
<html>
<head>
<mata charset="UTF-8" />
<title>分析生命周期</title>
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!--
-->
<!-- 准备好一个容器 -->
<div id="root">
<h2>当前的值是:{{n}}</h2>
<button @click="add">点我n+1</button>
<button @click="bye">点我销毁vm</button>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = false
new Vue({
el:'#root',
data:{
opacity:1,
n:1
},
methods:{
add(){
this.n++
},
bye(){
console.log('bye'),
this.$destroy()
}
},
beforeCreate() {
console.log('beforeCreate')
console.log(this)
//debugger
},
created() {
console.log('created')
console.log(this)
// debugger
},
beforeMount() {
console.log('beforeMount')
console.log(this)
// debugger
},
mounted() {
console.log('mounted')
console.log(this)
// debugger
},
beforeUpdate() {
console.log('beforeUpdate')
console.log(this)
// debugger
},
updated() {
console.log('updated')
console.log(this)
// debugger
},
beforeDestroy() {
console.log('beforeDestroy')
console.log(this)
// debugger
},
destroyed() {
console.log('destroyed')
console.log(this)
//debugger
},
})
</script>
</html>
Vue技术17.2分析生命周期
最新推荐文章于 2024-11-01 14:29:13 发布