- Vue.js 2 Design Patterns and Best Practices
- Paul Halliday
- 174字
- 2021-06-24 18:33:05
Lifecycle hooks
Lifecycle hooks such as created(), mounted(), destroyed(), and so on can be defined as functions within the class.
- created()
This allows for actions to be performed to a component before it is added into the DOM. Using this hook allows access to both data and events.
- mounted()
Mounted gives access to a component before it is rendered as well as after it has been rendered. It provides full access for interacting with the DOM and component.
- destroyed()
Everything that was attached to the component has been destroyed. It allows for cleanup of the component when it is removed from the DOM.
They'll be recognized and act the same way as expected without TypeScript. Here's an example when using the created and mounted hooks:
// Omitted
export default class App extends Vue {
name: string = 'Paul';
created() {
console.log(`Created: Hello ${this.name}`)
}
mounted() {
console.log(`Mounted: Hello ${this.name}`);
}
}
Now if we head over to the console, we can see that the message of 'Hello' is outputted with the name of Paul:

- 物聯(lián)網(wǎng)安全:理論、實踐與創(chuàng)新
- 物聯(lián)網(wǎng)之魂:物聯(lián)網(wǎng)協(xié)議與物聯(lián)網(wǎng)操作系統(tǒng)
- Oracle SOA Suite 11g Performance Tuning Cookbook
- IPv6網(wǎng)絡(luò)切片:使能千行百業(yè)新體驗
- Kong網(wǎng)關(guān):入門、實戰(zhàn)與進階
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)技術(shù)實戰(zhàn)指南
- 從實踐中學(xué)習(xí)手機抓包與數(shù)據(jù)分析
- 中國互聯(lián)網(wǎng)發(fā)展報告2021
- 物聯(lián)網(wǎng)與智慧廣電
- 互聯(lián)網(wǎng)視覺設(shè)計(全彩慕課版)
- 網(wǎng)絡(luò)攻防技術(shù)與實踐
- 華為LiteOS:快速上手物聯(lián)網(wǎng)應(yīng)用開發(fā)
- 一本書讀懂24種互聯(lián)網(wǎng)思維
- Exchange Server 2010 SP1/SP2管理實踐
- 數(shù)字經(jīng)濟時代的智慧城市與信息安全