官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 克什克腾旗| 隆昌县| 休宁县| 丹阳市| 琼结县| 东丰县| 化州市| 若羌县| 黎平县| 石家庄市| 武夷山市| 鱼台县| 泾源县| 水城县| 日土县| 策勒县| 伊金霍洛旗| 龙里县| 凌海市| 库伦旗| 郑州市| 娄烦县| 汝城县| 临漳县| 彭泽县| 尉犁县| 勃利县| 明光市| 铜川市| 沂南县| 呈贡县| 襄城县| 鹤峰县| 秭归县| 凯里市| 耒阳市| 蒙阴县| 永修县| 三明市| 大名县| 阳信县|