vue實例生命周期


實例生命周期

var vm = new Vue({
data: {
a: 1
},
created: function () {
// `this` 指向 vm 實例
console.log('a is: ' + this.a)
}
})
// -> "a is: 1"

There are also other hooks which will be called at different stages of the instance’s lifecycle, for example mountedupdated, and destroyed. All lifecycle hooks are called with their this context pointing to the Vue instance invoking it. You may have been wondering where the concept of “controllers” lives in the Vue world and the answer is: there are no controllers. Your custom logic for a component would be split among these lifecycle hooks.

也有一些其它的鈎子,在實例生命周期的不同階段調用,如 mounted、 updated 、destroyed 。鈎子的 this 指向調用它的 Vue 實例。一些用戶可能會問 Vue.js 是否有“控制器”的概念?答案是,沒有。組件的自定義邏輯可以分布在這些鈎子中。

生命周期圖示

下圖說明了實例的生命周期。你不需要立馬弄明白所有的東西,不過以后它會有幫助。

Lifecycle


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM