Skip to content

Commit 8ba88c2

Browse files
committed
docs: update
1 parent a57fb7e commit 8ba88c2

File tree

5 files changed

+110
-41
lines changed

5 files changed

+110
-41
lines changed

docs/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default defineConfig({
5757
],
5858
},
5959
markdown: {
60+
languages: ['js', 'ts'],
6061
codeTransformers: [
6162
transformerTwoslash({
6263
twoslasher: createTwoslasher({

docs/features/directives.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ Vue built-in directives for JSX.
1111
| `v-html` | :white_check_mark: | / |
1212
| `v-once` | :white_check_mark: | / |
1313

14+
## Dynamic Arguments
15+
16+
It is also possible to use a variable in a directive argument.
17+
Because JSX doesn't support `[]` keyword, use `$` instead.
18+
19+
## Modifiers
20+
21+
Modifiers are special postfixes denoted by a `_`, which indicate that a directive should be bound in some special way.
22+
Because JSX doesn't support `.` keyword, we use `_` instead.
23+
24+
```tsx
25+
<form onSubmit_prevent>
26+
<input v-model_number={value} />
27+
</form>
28+
```
29+
1430
## `v-if`, `v-else-if`, `v-else`
1531

1632
```tsx twoslash
@@ -80,27 +96,21 @@ const Comp = () => {
8096
return <div />
8197
}
8298

83-
// ---cut-start---
84-
// prettier-ignore
85-
// ---cut-end---
8699
export default () => (
87-
<Comp v-slots={{
88-
default: () => <>default slot</>,
89-
slot: ({ bar }) => <>{bar}</>
90-
}} />
100+
<Comp
101+
v-slots={{
102+
default: () => <>default slot</>,
103+
slot: ({ bar }) => <>{bar}</>,
104+
}}
105+
/>
91106
)
92107
```
93108

94109
:::
95110

96-
## Dynamic Arguments
97-
98-
It is also possible to use a variable in a directive argument.
99-
Because JSX doesn't support `[]` keyword, use `$` instead.
100-
101-
### `v-model`
111+
## `v-model`
102112

103-
```tsx
113+
```tsx twoslash
104114
import { ref } from 'vue'
105115

106116
const Comp = () => {
@@ -122,7 +132,7 @@ export default () => {
122132
}
123133
```
124134

125-
### `v-slot`
135+
## `v-slot`
126136

127137
```tsx twoslash
128138
export const Comp = () => {
@@ -150,14 +160,3 @@ export default () => (
150160
</Comp>
151161
)
152162
```
153-
154-
## Modifiers
155-
156-
Modifiers are special postfixes denoted by a `_`, which indicate that a directive should be bound in some special way.
157-
Because JSX doesn't support `.` keyword, we use `_` instead.
158-
159-
```tsx
160-
<form onSubmit_prevent>
161-
<input v-model_number={value} />
162-
</form>
163-
```

docs/features/macros.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Macros
22

3-
<StabilityLevel level="experimental" />
4-
53
A collection of macros. They are need to muanually enabled by set `macros` to `true`.
64

75
| Directive | Vue | Volar |
@@ -16,7 +14,7 @@ A collection of macros. They are need to muanually enabled by set `macros` to `t
1614

1715
::: code-group
1816

19-
```ts {6} [vite.config.ts]
17+
```ts {7} [vite.config.ts]
2018
import { defineConfig } from 'vite'
2119
import vueJsxVapor from 'vue-jsx-vapor/vite'
2220

@@ -29,7 +27,7 @@ export default defineConfig({
2927
})
3028
```
3129

32-
```ts {5} [tsm.config.ts]
30+
```ts {6} [tsm.config.ts]
3331
import vueJsxVapor from 'vue-jsx-vapor/volar'
3432

3533
export default {
@@ -145,18 +143,19 @@ defineComponent(
145143
- Will be inferred as a required prop when the expression ends with `!`.
146144
- The modified model's value can be read synchronously, without needing to `await nextTick()`. [Related issue](https://github.com/vuejs/core/issues/11080)
147145

148-
```tsx
146+
```tsx twoslash
149147
import { ref } from 'vue'
150148

151149
function Comp() {
152150
const modelValue = defineModel<string>()!
153151
modelValue.value = 'foo'
154152
return <div>{modelValue.value}</div>
153+
// ^?
155154
}
156155

157156
export default () => {
158157
const foo = ref('')
159-
return <Comp v-model={foo.value} />
158+
return <input value={foo.value} />
160159
}
161160
```
162161

@@ -208,11 +207,14 @@ function Comp<const T>() {
208207
)
209208
}
210209

210+
// ---cut-start---
211+
// prettier-ignore
212+
// ---cut-end---
211213
export default () => (
212214
<Comp<1>>
213215
<template v-slot={{ foo }}>{foo}</template>
214216
<template v-slot:title={{ bar }}>{bar}</template>
215-
// ^?
217+
// ^?
216218
</Comp>
217219
)
218220
```
@@ -221,7 +223,7 @@ export default () => (
221223

222224
Just like in Vue SFC.
223225

224-
```tsx
226+
```tsx twoslash
225227
import { useRef } from 'vue-jsx-vapor'
226228

227229
const Comp = <T,>({ foo = undefined as T }) => {
@@ -234,7 +236,7 @@ const Comp = <T,>({ foo = undefined as T }) => {
234236
export default () => {
235237
const compRef = useRef()
236238
compRef.value?.foo
237-
// ^?
239+
// ^?
238240

239241
return <Comp ref={compRef} foo={1 as const} />
240242
}
@@ -313,6 +315,7 @@ export default () => {
313315
}
314316
}
315317
`)
318+
316319
return <div class={styles.bar} />
317320
// ^?
318321
}

docs/features/use-ref.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ Automatically infer type for `useRef`. It's an alias of `shallowRef`.
44

55
## Basic Usage
66

7-
::: code-group
8-
9-
```tsx
10-
import { defineComponent, shallowRef as useRef } from 'vue'
7+
```tsx twoslash
8+
import { defineComponent } from 'vue'
9+
import { useRef } from 'vue-jsx-vapor'
1110
// or
12-
// import { useRef } from 'vue-jsx-vapor'
11+
// import { shallowRef as useRef } from 'vue'
1312

1413
export const Comp = defineComponent({
1514
setup() {

docs/introduction/migration.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,71 @@
44

55
1. Doesn't support hyphenated prop name and hyphenated component name.
66
2. `v-model` doesn't support Array Expression, use `v-model:$name$_trim={foo}` instead.
7-
3. Doesn't support `v-models` directive.
7+
3. Doesn't support `v-models` directive.
8+
4. Destructing props:
9+
10+
> [!CAUTION]
11+
> ❌ The destructuring of props in a functional component will cause loss of reactivity.
12+
13+
```tsx
14+
function Comp({ foo }) {
15+
return <div>{foo}</div>
16+
}
17+
18+
export default () => {
19+
const foo = ref('foo')
20+
return <Comp foo={foo.value} />
21+
}
22+
```
23+
24+
#### Two Solutions
25+
26+
1. ✅ Pass a ref variable as prop:
27+
28+
```tsx
29+
function Comp({ foo }) {
30+
return <div>{foo.value}</div>
31+
}
32+
33+
export default () => {
34+
const foo = ref('foo')
35+
return <Comp foo={foo} />
36+
}
37+
```
38+
39+
2. ✅ Set the macros option to true, then use the `defineComponent` macro for wrapping.
40+
41+
- Setup
42+
43+
```ts {7}
44+
// vite.config.ts
45+
import vueJsxVapor from 'vue-jsx-vapor/vite'
46+
47+
export default defineConfig({
48+
plugins: [
49+
vueJsxVapor({
50+
macros: true,
51+
}),
52+
]
53+
})
54+
55+
```
56+
57+
- Usage
58+
59+
```tsx
60+
import { defineComponent, ref } from 'vue'
61+
62+
const Comp = defineComponent(({ foo }) => {
63+
return <>{foo}</>
64+
})
65+
// Will be convert to:
66+
const Comp = defineComponent((_props) => {
67+
return <>{_props.foo}</>
68+
}, { props: ['foo'] })
69+
70+
export default () => {
71+
const foo = ref('foo')
72+
return <Comp foo={foo.value} />
73+
}
74+
```

0 commit comments

Comments
 (0)