<div id="box">
<h3 id="h3">{{msg}}</h3>
</div>
var vm = new Vue({
el: "#box",
data: {
msg: "hello"
},
methods: {
show: function () {
alert("執行了show函數");
}
},
beforeCreate() {
this.show();
},
created: function () {
this.show();
},
beforeMount: function () {
alert(document.getElementById("h3").innerText);
},
mounted: function () {
alert(document.getElementById("h3").innerText);
}
});
<div id="box">
<h3 id="h3">{{msg}}</h3>
<input type="button" value="OK" @click="changeData"/> //點擊按鈕,更改msg的值
</div>
var vm = new Vue({
el: "#box",
data: {
msg:"hello"
},
methods: {
changeData: function () {
this.msg = "world";
}
},
beforeUpdate: function () {
alert(document.getElementById("h3").innerText);
alert(this.msg);
},
updated: function () {
alert(document.getElementById("h3").innerText);
alert(this.msg);
}
});
var vm = new Vue({
el: "#box",
beforeDestroy: function () {
},
destroyed: function () {
}
});