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

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:

主站蜘蛛池模板: 新余市| 承德市| 宣城市| 孝昌县| 威海市| 奉节县| 昭苏县| 区。| 合作市| 小金县| 仁化县| 汝州市| 陈巴尔虎旗| 水城县| 竹山县| 鹰潭市| 屏边| 青神县| 岳西县| 乌兰察布市| 巍山| 洪雅县| 上杭县| 达拉特旗| 玉屏| 建宁县| 陕西省| 绍兴市| 佛教| 高邮市| 九寨沟县| 张家港市| 高州市| 镇原县| 厦门市| 姚安县| 民丰县| 堆龙德庆县| 信阳市| 罗平县| 嘉黎县|