测试vue的钩子函数
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<button @click="change">点我</button>
<h3 id="h3">我是{{life}}生物</h3>
</div>
<script src="../vue.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
life:'单细胞',
}
},
methods: {
change(){
this.life = '多细胞'
}
},
beforeCreate(){
alert(this.life)
},
created() {
alert(this.life)
},
beforeMount(){
let h3 = document.getElementById("h3").innerText
alert(h3)
},
mounted(){
let h3 = document.getElementById("h3").innerText
alert(h3)
},
beforeUpdate(){
let h3 = document.getElementById("h3").innerText
alert(h3)
},
updated(){
let h3 = document.getElementById("h3").innerText
alert(h3)
}
})
</script>
</body>
</html>
标签:life,vue,钩子,alert,getElementById,let,测试,h3,document 来源: https://www.cnblogs.com/mybloger/p/16212164.html