Vue3的生命周期函数
<html>
<head>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="app">
<button @click="show">{{message}}</button>
</div>
</body>
<script>
const app = Vue.createApp({
data(){
return {
message: 'hello world!'
}
},
methods:{
show(){
alert('click');
}
},
//Vue实例创建之前
beforeCreate(){
alert('before create');
},
//Vue实例创建完毕
created(){
alert('created');
},
//模板渲染之前
beforeMount(){
alert('beforeMount');
},
//模板渲染完毕
mounted(){
alert('mounted');
}
});
app.mount('#app');
</script>
</html>
beforeCreate 实例创建之前
createt 实例创建完毕
beforeMount 模板渲染之前
mounted 模板渲染完毕

浙公网安备 33010602011771号