|
2 | 2 |
|
3 | 3 | [](https://www.npmjs.com/package/vue-jsx-vapor)
|
4 | 4 |
|
5 |
| -Vue JSX Vapor. |
| 5 | +Vapor Mode of Vue JSX. |
6 | 6 |
|
7 |
| -[Docs](https://jsx-vapor.netlify.app/) . [Playground](https://repl.zmjs.dev/vuejs/vue-jsx-vapor) |
| 7 | +## Features |
8 | 8 |
|
9 |
| -## Install |
| 9 | +- ⚡️ High Performance: It has the same performance as Vue Vapor! |
| 10 | +- ⚒️ Directives: Support all build-in directives of Vue. |
| 11 | +- ✨ Macros: Support most macros of Vue, Friendly to JSX. |
| 12 | +- 🌈 Hot Module Replacement: Support functional components or defined by defineComponent. |
| 13 | +- 🦾 Type Safe: Provide Volar plugin support by install TS Macro (VSCode plugin). |
| 14 | +- ⚙️ ESLint: Provide an ESLint plugin for vue-jsx-vapor to automatically fix code. |
| 15 | + |
| 16 | +## Installation |
10 | 17 |
|
11 | 18 | ```bash
|
12 | 19 | npm i vue-jsx-vapor
|
13 | 20 | ```
|
14 | 21 |
|
15 |
| -> [!CAUTION] |
16 |
| -> ❌ The destructuring of props in a functional component will cause loss of reactivity. |
17 |
| -
|
18 |
| -```tsx |
19 |
| -function Comp({ foo }) { |
20 |
| - return <div>{foo}</div> |
21 |
| -} |
22 |
| - |
23 |
| -export default () => { |
24 |
| - const foo = ref('foo') |
25 |
| - return <Comp foo={foo.value} /> |
26 |
| -} |
27 |
| -``` |
28 |
| - |
29 |
| -#### Two Solutions |
30 |
| - |
31 |
| -1. ✅ Pass a ref variable as prop: |
32 |
| - |
33 |
| -```tsx |
34 |
| -function Comp({ foo }) { |
35 |
| - return <div>{foo.value}</div> |
36 |
| -} |
37 |
| - |
38 |
| -export default () => { |
39 |
| - const foo = ref('foo') |
40 |
| - return <Comp foo={foo} /> |
41 |
| -} |
42 |
| -``` |
43 |
| - |
44 |
| -2. ✅ Set the macros option to true, then use the `defineComponent` macro for wrapping. |
45 |
| - |
46 |
| -Setup |
47 |
| - |
48 |
| -```ts |
49 |
| -// vite.config.ts |
50 |
| -import vueJsxVapor from 'vue-jsx-vapor/vite' |
51 |
| - |
52 |
| -export default defineConfig({ |
53 |
| - plugins: [ |
54 |
| - vueJsxVapor({ |
55 |
| - macros: true, |
56 |
| - }), |
57 |
| - ] |
58 |
| -}) |
59 |
| - |
60 |
| -``` |
61 |
| - |
62 |
| -Usage |
63 |
| - |
64 |
| -```tsx |
65 |
| -const Comp = defineComponent(({ foo }) => { |
66 |
| - return <>{foo}</> |
67 |
| -}) |
68 |
| -// Will be convert to: |
69 |
| -const Comp = defineComponent((_props) => { |
70 |
| - return <>{_props.foo}</> |
71 |
| -}, { props: ['foo'] }) |
72 |
| - |
73 |
| -export default () => { |
74 |
| - const foo = ref('foo') |
75 |
| - return <Comp foo={foo.value} /> |
76 |
| -} |
77 |
| -``` |
78 |
| - |
79 |
| -## Typescript |
80 |
| - |
81 |
| -Because of vue-jsx-vapor support all directives and most macros of Vue,\ |
82 |
| -so we need the VSCode plugin [ts-macro](https://github.com/ts-macro/ts-macro) to use the `vue-jsx-vapor/volar` plugin for Typescript support.\ |
83 |
| -It works similarly to [@vue/language-tools](https://github.com/vuejs/language-tools) but only used for `ts` or `tsx` files. |
84 |
| - |
85 |
| -By default, after installing the `ts-macro` VSCode plugin, `ts-macro` will automatically load `vue-jsx-vapor/volar` by analyzing `vite.config.ts` and shared vueJsxVapor's options. so you don't need to config `tsm.config.ts`. But if you want, you can also configure it manually: |
86 |
| - |
87 |
| -```ts |
88 |
| -// tsm.config.ts |
89 |
| -import vueJsxVapor from 'vue-jsx-vapor/volar' |
90 |
| - |
91 |
| -export default { |
92 |
| - plugins: [ |
93 |
| - vueJsxVapor({ |
94 |
| - macros: true, |
95 |
| - }), |
96 |
| - ], |
97 |
| -} |
98 |
| - |
99 |
| -``` |
| 22 | +## Usage |
100 | 23 |
|
| 24 | +- [📜 Documentation]((https://jsx-vapor.netlify.app/)) |
| 25 | +- [🛰️ Playground](https://repl.zmjs.dev/vuejs/vue-jsx-vapor) |
101 | 26 |
|
102 | 27 | <details>
|
103 | 28 | <summary>Vite</summary><br>
|
|
0 commit comments