本篇文章為大家展示了Vue的生命周期有哪些,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

具體如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue的生命周期</title>
<script type="text/javascript" src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
</head>
<body>
<h2>Vue的生命周期</h2>
<hr>
<div id="app">
{{count}}
<p><button @click="add">Add</button></p>
</div>
<button οnclick="app.$destroy()">銷毀</button>
</body>
</html>
<script>
var app = new Vue({
el:'#app',
data:{
count:1
},
methods:{
add:function () {
this.count++
}
},
//有這么多鉤子函數(shù) 一共十個(gè)
//初始化之后
beforeCreate:function(){
console.log('1-beforeCreate 初始化之后');
},
//創(chuàng)建完成
created:function(){
console.log('2-created 創(chuàng)建完成');
},
//掛載之前
beforeMount:function(){
console.log('3-beforeMount 掛載之前');
},
//被創(chuàng)建
mounted:function(){
console.log('4-mounted 被創(chuàng)建');
},
//數(shù)據(jù)更新前
beforeUpdate:function(){
console.log('5-beforeUpdate 數(shù)據(jù)更新前');
},
//被更新后
updated:function(){
console.log('6-updated 被更新后');
},
//
activated:function(){
console.log('7-activated');
},
//
deactivated:function(){
console.log('8-deactivated');
},
//銷毀之前
beforeDestroy:function(){
console.log('9-beforeDestroy 銷毀之前');
},
//銷毀之后
destroyed:function(){
console.log('10-destroyed 銷毀之后')
}
})
</script>運(yùn)行結(jié)果:

上述內(nèi)容就是Vue的生命周期有哪些,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
本文題目:Vue的生命周期有哪些-創(chuàng)新互聯(lián)
文章地址:http://www.chinadenli.net/article16/dgedgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、網(wǎng)站內(nèi)鏈、建站公司、外貿(mào)網(wǎng)站建設(shè)、服務(wù)器托管、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容