Skip to content

Migration Guide > Props Default Function this Access の翻訳元ファイル追加と翻訳 #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const sidebar = {
'migration/global-api-treeshaking',
'migration/inline-template-attribute',
'migration/keycode-modifiers',
'migration/props-default-this',
'migration/render-function-api',
'migration/slots-unification',
'migration/transition',
Expand Down
32 changes: 32 additions & 0 deletions src/guide/migration/props-default-this.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: プロパティのデフォルト値ファクトリ関数の `this` アクセス
badges:
- breaking
---

# プロパティのデフォルト値ファクトリ関数の `this` アクセス <MigrationBadges :badges="$frontmatter.badges" />

プロパティのデフォルト値ファクトリ関数が `this` にアクセスできなくなりました。

代わりの方法は以下です。

- コンポーネントが受け取った生のプロパティは、引数としてデフォルト関数に渡されます。

- [inject](../composition-api-provide-inject.md) API がデフォルト関数の内部で使用できます。

```js
import { inject } from 'vue'

export default {
props: {
theme: {
default (props) {
// `props` 引数はコンポーネントに渡される生の値で、
// 型やデフォルトの強制より前のものです。
// また、`inject` を使用して注入されたプロパティにアクセスすることもできます。
return inject('theme', 'default-theme')
}
}
}
}
```