Skip to content

Commit 3381256

Browse files
committed
docs: [zh-cn] hook merging
1 parent 08bdc96 commit 3381256

File tree

8 files changed

+23
-8
lines changed

8 files changed

+23
-8
lines changed

docs/en/pipeline/hooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,6 @@ Similar to component lifecycle hooks, the following route lifecycle hooks:
137137
- `activate`
138138
- `deactivate`
139139

140-
...are merged during class extension or mixins. For example, if your component defines a route `data` hook, and uses a mixin that also provides a route `data` hook, both hooks will get called (mixin hooks called first) and the resolved data from all hooks will be merged together.
140+
...are "merged" during option merges (i.e. class extension or mixins). For example, if your component defines a route `data` hook, and uses a mixin that also provides a route `data` hook, both hooks will get called (mixin hooks called first) and the resolved data from all hooks will be merged together.
141141

142-
Note that validation hooks like `canActivate`, `canDeactivate` and `canReuse` are always overwritten by the newer value.
142+
Note that validation hooks like `canActivate`, `canDeactivate` and `canReuse` are always overwritten by the newer value during option merges.

docs/zh-cn/pipeline/activate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
调用 `transition.next()` 可以断定( resolve )这个钩子函数。注意,这里调用 `transition.abort()` 并不会把应用回退到前一个路由状态因为此时切换已经被确认合法了。
1010

11-
### 返回值
11+
### 预期返回值
1212

1313
- 可选择性返回 Promise。
1414
- `resolve` -> `transition.next()`

docs/zh-cn/pipeline/can-activate.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
调用 `transition.next()` 可以断定( resolve )此钩子函数。调用 `transition.abort()` 可以无效化并取消此次切换。
1010

11-
### 返回值
11+
### 预期返回值
1212

1313
- 可选择性返回 Promise :
1414

1515
- `resolve(true)` -> `transition.next()`
1616
- `resolve(false)` -> `transition.abort()`
1717
- `reject(reason)` -> `transition.abort(reason)`
1818

19+
1920
- 可选择性返回 Boolean 值:
2021

2122
- `true` -> `transition.next()`

docs/zh-cn/pipeline/can-deactivate.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
调用 `transition.next()` 可以断定( resolve )此钩子函数。调用 `transition.abort()` 可以无效化并取消此次切换。
1010

11-
### 返回值
11+
### 预期返回值
1212

1313
- 可选择性返回 Promise :
1414

1515
- `resolve(true)` -> `transition.next()`
1616
- `resolve(false)` -> `transition.abort()`
1717
- `reject(reason)` -> `transition.abort(reason)`
1818

19+
1920
- 可选择性返回 Boolean 值:
2021

2122
- `true` -> `transition.next()`

docs/zh-cn/pipeline/can-reuse.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
`canResule` 钩子中只能访问 `transition.to``transition.from`
1212

13-
### 返回值
13+
### 预期返回值
1414

1515
- 必须返回 Boolean 类型,其他等效的假值( Falsy values )会当作 `false` 对待。
1616

docs/zh-cn/pipeline/data.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
调用 `transition.next(data)` 会为组件的 `data` 相应属性赋值。例如,使用 `{ a: 1, b: 2 }` ,路由会调用 `component.$set('a', 1)` 以及 `component.$set('b', 2)`
1010

11-
### 返回值
11+
### 预期返回值
1212

1313
- 可选择性返回一个Promise
1414
- `resolve(data)` -> `transition.next(data)`
1515
- `reject(reason)` -> `transition.abort(reason)`
1616

17+
1718
- 或者,返回一个包含 Promise 的对象。见后文 [Promise 语法糖](#promise-%E8%AF%AD%E6%B3%95%E7%B3%96)
1819

1920
### 详情

docs/zh-cn/pipeline/deactivate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
调用 `transition.next()` 可以断定( resolve )这个钩子函数。注意,这里调用 `transition.abort()` 并不会把应用回退到前一个路由状态因为此时切换已经被确认合法了。
1010

11-
### 返回值
11+
### 预期返回值
1212

1313
- 可选择性返回 Promise
1414
- `resolve` -> `transition.next()`

docs/zh-cn/pipeline/hooks.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,15 @@ route: {
128128
```
129129

130130
查看 vue-router 中的[高级示例](https://github.com/vuejs/vue-router/tree/dev/example/advanced)
131+
132+
### 钩子合并
133+
134+
和组件本身的生命周期钩子一样,以下路由生命周期钩子:
135+
136+
- `data`
137+
- `activate`
138+
- `deactivate`
139+
140+
也会在合并选项时(扩展类或是使用 mixins)被合并。举例来说,如果你的组件本身定义了一个路由 `data` 钩子,而这个组件所调用的一个 mixin 也定义了一个路由 `data` 钩子,则这两个钩子都会被调用,并且各自返回的数据将会被最终合并到一起。
141+
142+
需要注意的是,验证类钩子,比如 `canActivate`, `canDeactivate``canReuse` 在合并选项时会直接被新值覆盖。

0 commit comments

Comments
 (0)