- Aurelia 教程
- Aurelia - 首頁
- Aurelia - 概述
- Aurelia - 環境搭建
- Aurelia - 第一個應用
- Aurelia - 元件
- Aurelia - 元件生命週期
- Aurelia - 自定義元素
- Aurelia - 依賴注入
- Aurelia - 配置
- Aurelia - 外掛
- Aurelia - 資料繫結
- Aurelia - 繫結行為
- Aurelia - 轉換器
- Aurelia - 事件
- Aurelia - 事件聚合器
- Aurelia - 表單
- Aurelia - HTTP
- Aurelia - Refs
- Aurelia - 路由
- Aurelia - 歷史記錄
- Aurelia - 動畫
- Aurelia - 對話方塊
- Aurelia - 本地化
- Aurelia - 工具
- Aurelia - 打包
- Aurelia - 除錯
- Aurelia - 社群
- Aurelia - 最佳實踐
- Aurelia 有用資源
- Aurelia - 快速指南
- Aurelia - 有用資源
- Aurelia - 討論
Aurelia - 元件生命週期
Aurelia 使用元件生命週期方法來操作元件的生命週期。本章將向您展示這些方法並解釋元件的生命週期。
constructor() − 建構函式用於初始化用類建立的物件。此方法首先被呼叫。如果您沒有指定此方法,則將使用預設建構函式。
created(owningView, myView) − 一旦檢視和檢視模型建立並連線到控制器,就會呼叫此方法。此方法接受兩個引數。第一個引數是宣告元件的檢視(owningView)。第二個是元件檢視(myView)。
bind(bindingContext, overrideContext) − 在這一點上,繫結已經開始。第一個引數表示元件的繫結上下文。第二個是overrideContext。此引數用於新增其他上下文屬性。
attached() − 一旦元件附加到 DOM,就會呼叫 attached 方法。
detached() − 此方法與attached相反。當元件從 DOM 中移除時,會呼叫它。
unbind() − 最後一個生命週期方法是unbind。當元件取消繫結時,會呼叫它。
當您想要對元件有更高的控制權時,生命週期方法非常有用。當您需要在元件生命週期的某個點觸發某些功能時,可以使用它們。
所有生命週期方法如下所示。
app.js
export class App {
constructor(argument) {
// Create and initialize your class object here...
}
created(owningView, myView) {
// Invoked once the component is created...
}
bind(bindingContext, overrideContext) {
// Invoked once the databinding is activated...
}
attached(argument) {
// Invoked once the component is attached to the DOM...
}
detached(argument) {
// Invoked when component is detached from the dom
}
unbind(argument) {
// Invoked when component is unbound...
}
}
廣告