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

update props-default-this.md #737

Merged
merged 1 commit into from
Sep 19, 2021
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: 4 additions & 4 deletions src/guide/migration/props-default-this.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ badges:

生成 prop 默认值的工厂函数不再能访问 `this`。

替代方案
取而代之的是

- 把组件接收到的原始 prop 作为参数传递给默认函数
- 组件接收到的原始 prop 将作为参数传递给默认函数

- [inject](../composition-api-provide-inject.md) API 可以在默认函数中使用。

Expand All @@ -21,8 +21,8 @@ export default {
props: {
theme: {
default (props) {
// `props` 是传递给组件的原始值。
// 在任何类型/默认强制转换之前
// `props` 是传递给组件的、
// 在任何类型/默认强制转换之前的原始值,
// 也可以使用 `inject` 来访问注入的 property
return inject('theme', 'default-theme')
}
Expand Down