Skip to content

Commit c51fccb

Browse files
authored
Merge pull request #631 from ZiF1R/patch-1
2 parents c5de6e9 + e2fbf4c commit c51fccb

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/api/sfc-script-setup.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ const attrs = useAttrs()
223223
`<script setup>` は、通常の `<script>` と一緒に使うことができます。次のことが必要な場合は、通常の `<script>` が必要になることがあります:
224224

225225
- `inheritAttrs` や、プラグインで有効になるカスタムオプションなど、`<script setup>` では表現できないオプションを宣言する
226-
- 名前付きのエクスポートを宣言する
226+
- 名前付きのエクスポートを宣言する (TypeScript の型を含む)
227227
- 副作用を実行したり、一度しか実行してはいけないオブジェクトを作成する
228228

229229
```vue
@@ -265,6 +265,23 @@ const post = await fetch(`/api/post/1`).then(r => r.json())
265265

266266
## TypeScript のみの機能
267267

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+
268285
### 型のみの props/emit 宣言
269286

270287
`defineProps``defineEmits` にリテラル型の引数を渡すことで、純粋な型の構文を使って props や emits を宣言することもできます:

0 commit comments

Comments
 (0)