【vue.js】生命周期——beforeCreate、created、beforeMount、mounted、beforeUpdate、updated、beforeDesotry、destoryed
<!doctype html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><script
·
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app" ref="app">
{{ name }}
</div>
</body>
<script>
let vm=new Vue({
el:"#app",
data:{
name:"liuting",
},
beforeCreate(){
console.log("创建前:");
console.log(this.$el);
console.log(this.$data);
},
created(){
console.log("创建完成:");
console.log(this.$el);
console.log(this.$data);
},
beforeMount(){
console.log("挂载前:");
console.log(this.$el);
console.log(this.$data);
},
mounted(){
console.log("挂载完成:");
console.log(this.$el);
console.log(this.$data);
},
beforeUpdate(){
console.log('=即将更新渲染=');
let name = this.$refs.app.innerHTML;
console.log('name:'+name);
},
updated(){
console.log('==更新成功==');
let name = this.$refs.app.innerHTML;
console.log('name:'+name);
},
/*beforeDestory(){
console.log("销毁前:");
},
destoryed(){
console.log("销毁完成:");
}*/
});
</script>
</html>
更多推荐
已为社区贡献5条内容
所有评论(0)