- 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:

- Hands-On Chatbot Development with Alexa Skills and Amazon Lex
- SD-WAN架構(gòu)與技術(shù)(第2版)
- 正在爆發(fā)的互聯(lián)網(wǎng)革命
- 通信簡史:從信鴿到6G+
- 物聯(lián)網(wǎng)與無線傳感器網(wǎng)絡(luò)
- 區(qū)塊鏈輕松上手:原理、源碼、搭建與應(yīng)用
- IPv6網(wǎng)絡(luò)切片:使能千行百業(yè)新體驗(yàn)
- 網(wǎng)管第一課:網(wǎng)絡(luò)操作系統(tǒng)與配置管理
- 5G技術(shù)核心與增強(qiáng):從R15到R17
- 移動(dòng)互聯(lián)網(wǎng)新思維
- 工業(yè)以太網(wǎng)技術(shù):AFDX/TTE網(wǎng)絡(luò)原理、接口、互連與安全
- Cisco無線局域網(wǎng)配置基礎(chǔ)
- INSTANT Social Media Marketing with HootSuite
- 通信系統(tǒng)實(shí)戰(zhàn)筆記:無處不在的信號處理
- 一本書讀懂移動(dòng)物聯(lián)網(wǎng)