File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ export default {
34
34
しかし、` props ` はリアクティブなので、** ES6 の分割代入を使うことができません。** props のリアクティブを削除してしまうからです。
35
35
:::
36
36
37
- もし、props を分割代入する必要がある場合は、` setup ` 関数内で [ toRefs] ( reactivity-fundamentals.html#destructuring-reactive-state ) を使うことによって安全に分割代入を行うことができます。
37
+ もし、props を分割代入する必要がある場合は、` setup ` 関数内で [ toRefs] ( reactivity-fundamentals.html#destructuring-reactive-state ) を使うことによって分割代入を行うことができます:
38
38
39
39
``` js
40
40
// MyBook.vue
@@ -48,6 +48,20 @@ setup(props) {
48
48
}
49
49
```
50
50
51
+ ` title ` オプションのプロパティである場合、 ` props ` から抜けている可能性があります。その場合、 ` toRefs ` では ` title ` の ref はつくられません。代わりに ` toRef ` を使う必要があります:
52
+
53
+ ``` js
54
+ // MyBook.vue
55
+
56
+ import { toRef } from ' vue'
57
+
58
+ setup (props ) {
59
+ const title = toRef (props, ' title' )
60
+
61
+ console .log (title .value )
62
+ }
63
+ ```
64
+
51
65
### コンテキスト
52
66
53
67
` setup ` 関数に渡される第二引数は ` context ` です。` context ` は 3 つのコンポーネントプロパティを公開する一般的な JavaScript オブジェクトです。:
You can’t perform that action at this time.
0 commit comments