Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

docs: composition-api-lifecycle-hooks.md #148

Merged
merged 4 commits into from
Sep 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/guide/composition-api-lifecycle-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

> 本指南假定你已经阅读了 [Composition API 简介](composition-api-introduction.html)和[响应式基础](reactivity-fundamentals.html)。如果你不熟悉组合 API,请先阅读这篇文章。

你可以通过在生命周期钩子前面加上“on”来访问组件的生命周期钩子。
<VideoLesson href="https://www.vuemastery.com/courses/vue-3-essentials/lifecycle-hooks" title="Learn about how Lifecycle Hooks work with Vue Mastery">在 Vue Mastery 上观看关于生命周期钩子的免费视频</VideoLesson>

你可以通过在生命周期钩子前面加上 “on” 来访问组件的生命周期钩子。

下表包含如何在 [setup ()](composition-api-setup.html) 内部调用生命周期钩子:

| 选项 API | Hook inside inside `setup` |
| 选项 API | Hook inside `setup` |
| ----------------- | -------------------------- |
| `beforeCreate` | Not needed\* |
| `created` | Not needed\* |
Expand All @@ -24,7 +26,7 @@
因为 `setup` 是围绕 `beforeCreate` 和 `created` 生命周期钩子运行的,所以不需要显式地定义它们。换句话说,在这些钩子中编写的任何代码都应该直接在 `setup` 函数中编写。
:::

这些函数接受在组件调用钩子时将执行的回调:
这些函数接受一个回调函数,当钩子被组件调用时将会被执行:

```js
// MyBook.vue
Expand Down