File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ const attrs = useAttrs()
223
223
` <script setup> ` は、通常の ` <script> ` と一緒に使うことができます。次のことが必要な場合は、通常の ` <script> ` が必要になることがあります:
224
224
225
225
- ` inheritAttrs ` や、プラグインで有効になるカスタムオプションなど、` <script setup> ` では表現できないオプションを宣言する
226
- - 名前付きのエクスポートを宣言する
226
+ - 名前付きのエクスポートを宣言する (TypeScript の型を含む)
227
227
- 副作用を実行したり、一度しか実行してはいけないオブジェクトを作成する
228
228
229
229
``` vue
@@ -265,6 +265,23 @@ const post = await fetch(`/api/post/1`).then(r => r.json())
265
265
266
266
## TypeScript のみの機能
267
267
268
+ ### 追加タイプのエクスポート
269
+
270
+ 上記のように、SFC から追加タイプをエクスポートするには、それらを ` <script setup> ` ブロックの隣の追加 ` <script> ` ブロックに移動する必要があります。
271
+
272
+ 例:
273
+ ``` vue
274
+ <script lang="ts">
275
+ export type SizeOptions = 'small' | 'medium' | 'large';
276
+ </script>
277
+
278
+ <script lang="ts" setup>
279
+ defineProps({
280
+ size: { type: String as PropType<SizeOptions> },
281
+ })
282
+ </script>
283
+ ```
284
+
268
285
### 型のみの props/emit 宣言
269
286
270
287
` defineProps ` や ` defineEmits ` にリテラル型の引数を渡すことで、純粋な型の構文を使って props や emits を宣言することもできます:
You can’t perform that action at this time.
0 commit comments