Vue的生命周期操作示例
更新時(shí)間:2019年09月17日 09:31:58 作者:Json____
這篇文章主要介紹了Vue的生命周期操作,結(jié)合實(shí)例形式分析了vue生命周期中各個(gè)函數(shù)的運(yùn)行步驟,需要的朋友可以參考下
本文實(shí)例講述了Vue的生命周期操作。分享給大家供大家參考,具體如下:
<!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>
<h1>Vue的生命周期</h1>
<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é)果:

感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測試上述代碼運(yùn)行效果。
希望本文所述對大家vue.js程序設(shè)計(jì)有所幫助。
相關(guān)文章
Vue2.0 實(shí)現(xiàn)歌手列表滾動及右側(cè)快速入口功能
這篇文章主要介紹了Vue2.0實(shí)現(xiàn)歌手列表滾動及右側(cè)快速入口功能,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-08-08
vue中使用moment設(shè)置倒計(jì)時(shí)的方法
這篇文章給大家介紹了vue中使用moment設(shè)置倒計(jì)時(shí)的方法,文中通過代碼示例給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-02-02
基于Vue?+?ElementUI實(shí)現(xiàn)可編輯表格及校驗(yàn)
這篇文章主要給大家介紹了基于Vue?+?ElementUI?實(shí)現(xiàn)可編輯表格及校驗(yàn),文中有詳細(xì)的代碼講解和實(shí)現(xiàn)思路,講解的非常詳細(xì),有需要的朋友可以參考下2023-08-08

