-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(macros): missing single-define ts types * feat(docs): add single-define macors docs * refactor(docs): merge defineEmit & defineProp page * docs: update * chore: add changesets file --------- Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
- Loading branch information
1 parent
b9818a3
commit 53203a2
Showing
7 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'unplugin-vue-macros': minor | ||
--- | ||
|
||
introduce `singleDefine` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# singleDefine | ||
|
||
<small>Stability: <code class="!text-yellow-600">unstable</code></small> | ||
|
||
Declare single props and events with `defineProp` & `defineEmit`. | ||
|
||
| Features | Supported | | ||
| :--------: | :----------------: | | ||
| Vue 3 | :white_check_mark: | | ||
| Nuxt 3 | :white_check_mark: | | ||
| Vue 2 | :white_check_mark: | | ||
| TypeScript | :white_check_mark: | | ||
|
||
::: warning | ||
|
||
`defineProp` can not be used with `defineProps` at same time | ||
|
||
`defineEmit` can not be used with `defineEmits` at same time | ||
|
||
::: | ||
|
||
## Basic Usage | ||
|
||
```vue | ||
<script setup> | ||
// Declare prop | ||
const count = defineProp('count') | ||
// Declare event | ||
const increment = defineEmit('increment') | ||
// access prop value | ||
console.log(count.value) | ||
// emit event | ||
increment() | ||
</script> | ||
``` | ||
|
||
## With Options & Validation | ||
|
||
```vue | ||
<script setup> | ||
// Declare prop with options | ||
const count = defineProp('count', { | ||
type: Number, | ||
required: true, | ||
default: 0, | ||
validator: (value) => value < 20, | ||
}) | ||
// Declare event with validation | ||
const increment = defineEmit('increment', (value) => value < 20) | ||
</script> | ||
``` | ||
|
||
## Using Multiple Times | ||
|
||
```vue | ||
<script setup> | ||
const count = defineProp('count') | ||
const maxCount = defineProp('maxCount') | ||
const increment = defineEmit('increment') | ||
const decrement = defineEmit('decrement') | ||
</script> | ||
``` | ||
|
||
## TypeScript | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
// Declare prop of type number | ||
const count = defineProp<number>('count') | ||
count.value | ||
// ^ type number | ||
const increment = defineEmit('bar', (value: number) => value < 20) | ||
increment(2) // pass | ||
increment('2') // TS type error | ||
</script> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# singleDefine | ||
|
||
<small>Stability: <code class="!text-yellow-600">unstable</code></small> | ||
|
||
Declare single props and events with `defineProp` & `defineEmit`. | ||
|
||
| Features | Supported | | ||
| :--------: | :----------------: | | ||
| Vue 3 | :white_check_mark: | | ||
| Nuxt 3 | :white_check_mark: | | ||
| Vue 2 | :white_check_mark: | | ||
| TypeScript | :white_check_mark: | | ||
|
||
::: warning | ||
|
||
`defineProp` can not be used with `defineProps` at same time | ||
|
||
`defineEmit` can not be used with `defineEmits` at same time | ||
|
||
::: | ||
|
||
## Basic Usage | ||
|
||
```vue | ||
<script setup> | ||
// Declare prop | ||
const count = defineProp('count') | ||
// Declare event | ||
const increment = defineEmit('increment') | ||
// access prop value | ||
console.log(count.value) | ||
// emit event | ||
increment() | ||
</script> | ||
``` | ||
|
||
## With Options & Validation | ||
|
||
```vue | ||
<script setup> | ||
// Declare prop with options | ||
const count = defineProp('count', { | ||
type: Number, | ||
required: true, | ||
default: 0, | ||
validator: (value) => value < 20, | ||
}) | ||
// Declare event with validation | ||
const increment = defineEmit('increment', (value) => value < 20) | ||
</script> | ||
``` | ||
|
||
## Using Multiple Times | ||
|
||
```vue | ||
<script setup> | ||
const count = defineProp('count') | ||
const maxCount = defineProp('maxCount') | ||
const increment = defineEmit('increment') | ||
const decrement = defineEmit('decrement') | ||
</script> | ||
``` | ||
|
||
## TypeScript | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
// Declare prop of type number | ||
const count = defineProp<number>('count') | ||
count.value | ||
// ^ type number | ||
const increment = defineEmit('bar', (value: number) => value < 20) | ||
increment(2) // pass | ||
increment('2') // TS type error | ||
</script> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters