# vue的生命週期 ###### tags: `Java Web-vue`  ### vue語法 ```htmlembedded= var vue = new Vue({ "el":"#div0", data:{ msg:1 }, methods:{ changeMsg:function(){ this.msg = this.msg + 1 ; } }, /*vue对象创建之前*/ beforeCreate:function(){ console.log("beforeCreate:vue对象创建之前---------------"); console.log("msg:"+this.msg); }, /*vue对象创建之后*/ created:function(){ console.log("created:vue对象创建之后---------------"); console.log("msg:"+this.msg); }, /*数据装载之前*/ beforeMount:function(){ console.log("beforeMount:数据装载之前---------------"); console.log("span:"+document.getElementById("span").innerText); }, /*数据装载之后*/ mounted:function(){ console.log("mounted:数据装载之后---------------"); console.log("span:"+document.getElementById("span").innerText); }, beforeUpdate:function(){ console.log("beforeUpdate:数据更新之前---------------"); console.log("msg:"+this.msg); console.log("span:"+document.getElementById("span").innerText); }, updated:function(){ console.log("Updated:数据更新之后---------------"); console.log("msg:"+this.msg); console.log("span:"+document.getElementById("span").innerText); } }); ``` #### vue創建前 msg未定義  #### vue創建後 mgs成功定義  #### vue數據裝載之前 無法顯示span的內部文本  #### vue數據裝載之後 顯示span的內部文本  #### vue數據更新之前  #### vue數據更新之後 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up