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

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:

主站蜘蛛池模板: 明水县| 辽阳市| 高邮市| 淅川县| 福鼎市| 昭苏县| 潢川县| 松桃| 延长县| 鸡泽县| 田林县| 望奎县| 秭归县| 平顶山市| 禹城市| 柳州市| 太白县| 赞皇县| 塔河县| 文成县| 山东省| 开江县| 连江县| 当涂县| 石台县| 五寨县| 理塘县| 壶关县| 静安区| 临夏市| 时尚| 玛沁县| 陇南市| 科尔| 荔波县| 隆德县| 龙泉市| 灵丘县| 中牟县| 神木县| 肃宁县|