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

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:

主站蜘蛛池模板: 定陶县| 赣州市| 温泉县| 长垣县| 河北区| 灵寿县| 巴楚县| 阿勒泰市| 文登市| 运城市| 台安县| 乌拉特中旗| 哈巴河县| 宁安市| 拉萨市| 嘉义县| 乌鲁木齐市| 塔河县| 治县。| 南投市| 屏山县| 九寨沟县| 剑川县| 灵台县| 涟水县| 象山县| 五常市| 河南省| 孝义市| 布尔津县| 中西区| 合山市| 莱西市| 海淀区| 全南县| 韩城市| 乌什县| 集安市| 永康市| 教育| 称多县|