|
11 | 11 |
|
12 | 12 | This project is community-driven. If you would like to support this project, consider joining the [Insiders Program](https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition) to improve the sustainability of this project and unlock more features.
|
13 | 13 |
|
14 |
| -<!-- |
15 |
| -
|
16 |
| -## Usage |
17 |
| -
|
18 |
| -<details> |
19 |
| -<summary>Setup for Vue 2</summary> |
20 |
| -
|
21 |
| -1. Add `@vue/runtime-dom` |
22 |
| -
|
23 |
| -This extension requires Vue 3 types from the `@vue/runtime-dom`. |
24 |
| -
|
25 |
| -Vue 3 and Vue 2.7 has built-in JSX types. For Vue version \<= 2.6.14 you need to add JSX types by install `@vue/runtime-dom`: |
26 |
| -
|
27 |
| -```jsonc |
28 |
| -// package.json |
29 |
| -{ |
30 |
| - "devDependencies": { |
31 |
| - "@vue/runtime-dom": "latest" |
32 |
| - } |
33 |
| -} |
34 |
| -``` |
35 |
| -
|
36 |
| -2. Remove `Vue.extend` |
37 |
| -
|
38 |
| -Template type-checking is not supported with `Vue.extend`. You can use [composition-api](https://github.com/vuejs/composition-api), [vue-class-component](https://github.com/vuejs/vue-class-component), or `export default { ... }` instead of `export default Vue.extend`. |
39 |
| -
|
40 |
| -Here is a compatibility table for different ways of writing the script blocks: |
41 |
| -
|
42 |
| -| | Component options type-checking in `<script>` | Interpolation type-checking in `<template>` | Cross-component props type-checking | |
43 |
| -|:-----------------------------------------|:----------------------------------------------|:--------------------------------------------|:------------------------------------| |
44 |
| -| `export default { ... }` with JS | Not supported | Not supported | Not supported | |
45 |
| -| `export default { ... }` with TS | Not supported | Supported but deprecated | Supported but deprecated | |
46 |
| -| `export default Vue.extend({ ... })` with JS | Not supported | Not supported | Not supported | |
47 |
| -| `export default Vue.extend({ ... })` with TS | Limited (supports `data` types but not `props` types) | Limited | Not supported | |
48 |
| -| `export default defineComponent({ ... })` | Supported | Supported | Supported | |
49 |
| -| Class component | Supported | Supported with additional code ([#21](https://github.com/vuejs/language-tools/issues/21)) | Supported with [additional code](https://github.com/vuejs/language-tools/pull/750#issuecomment-1023947885) | |
50 |
| -
|
51 |
| -Note that you can use `defineComponent` even for components that are using the `Options API`. |
52 |
| -
|
53 |
| -3. Support for Vue 2 template |
54 |
| -
|
55 |
| -Volar preferentially supports Vue 3. Vue 3 and Vue 2 templates have some differences. You need to set the `target` option to support the Vue 2 templates. |
56 |
| -
|
57 |
| -```jsonc |
58 |
| -// tsconfig.json |
59 |
| -{ |
60 |
| - "compilerOptions": { |
61 |
| - // ... |
62 |
| - }, |
63 |
| - "vueCompilerOptions": { |
64 |
| - "target": 2.7, |
65 |
| - // "target": 2, // For Vue version <= 2.6.14 |
66 |
| - } |
67 |
| -} |
68 |
| -``` |
69 |
| -
|
70 |
| -4. remove `.d.ts` files if they exist. |
71 |
| -
|
72 |
| -For projects generated by the [Vue CLI](https://cli.vuejs.org/), `.d.ts` files are included. Remove these files. |
73 |
| -
|
74 |
| -``` |
75 |
| -rm src/shims-tsx.d.ts src/shims-vue.d.ts |
76 |
| -``` |
77 |
| -
|
78 |
| -</details> |
79 |
| -
|
80 |
| -<details> |
81 |
| -<summary>Define Global Components</summary> |
82 |
| -
|
83 |
| -PR: https://github.com/vuejs/vue-next/pull/3399 |
84 |
| -
|
85 |
| -Local components, Built-in components, native HTML elements Type-Checking is available with no configuration. |
86 |
| -
|
87 |
| -For Global components, you need to define `GlobalComponents` interface, for example: |
88 |
| -
|
89 |
| -```typescript |
90 |
| -// components.d.ts |
91 |
| -declare module 'vue' { // Vue >= 2.7 |
92 |
| -// declare module '@vue/runtime-dom' { // Vue <= 2.6.14 |
93 |
| - export interface GlobalComponents { |
94 |
| - RouterLink: typeof import('vue-router')['RouterLink'] |
95 |
| - RouterView: typeof import('vue-router')['RouterView'] |
96 |
| - } |
97 |
| -} |
98 |
| -
|
99 |
| -export {} |
100 |
| -``` |
101 |
| -
|
102 |
| -</details> |
103 |
| -
|
104 |
| -## Notes |
105 |
| -
|
106 |
| -### Vetur |
107 |
| -
|
108 |
| -You need to disable Vetur to avoid conflicts. |
109 |
| -
|
110 |
| -Recommended use css / less / scss as `<style>` language, because these base on [vscode-css-languageservice](https://github.com/microsoft/vscode-css-languageservice) to provide reliable language support. |
111 |
| -
|
112 |
| -If use postcss / stylus / sass, you need to install additional extension for syntax highlighting. I tried these and it works, you can also choose others. |
113 |
| -
|
114 |
| -- postcss: [language-postcss](https://marketplace.visualstudio.com/items?itemName=cpylua.language-postcss). |
115 |
| -- stylus: [language-stylus](https://marketplace.visualstudio.com/items?itemName=sysoev.language-stylus) |
116 |
| -- sass: [Sass](https://marketplace.visualstudio.com/items?itemName=Syler.sass-indented) |
117 |
| -
|
118 |
| -Volar does not include ESLint and Prettier, but the official [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) extensions support Vue, so you could install these yourself if needed. |
119 |
| -
|
120 |
| -If using Vetur's [Customizable Scaffold Snippets](https://vuejs.github.io/vetur/guide/snippet.html#customizable-scaffold-snippets), recommend use [Snippet Generator](https://marketplace.visualstudio.com/items?itemName=wenfangdu.snippet-generator) convert to VSCode Snippets. There are also snippets on the VSCode Marketplace, such as Sarah Drasner's [Vue VSCode Snippets](https://marketplace.visualstudio.com/items?itemName=sdras.vue-vscode-snippets), if you prefer ready-made snippets without customization. |
121 |
| -
|
122 |
| -If VSCode gives an error for `class` and `slot` like this: |
123 |
| -
|
124 |
| -<kbd><img width="483" src="https://user-images.githubusercontent.com/3253920/145134536-7bb090e9-9dcd-4a61-8096-3c47d6c1a699.png" /></kbd> |
125 |
| -
|
126 |
| -This is because one of the packages installed in your project uses `@types/react` which breaks some parts of Volar. |
127 |
| -
|
128 |
| -Please see the following solutions: |
129 |
| -- https://github.com/vuejs/language-tools/discussions/592 |
130 |
| -- https://github.com/vuejs/language-tools/discussions/592#discussioncomment-1763880 |
131 |
| -
|
132 |
| -### Recursive components |
133 |
| -
|
134 |
| -Volar can't typecheck recursive components out of the box due to TS limitation. |
135 |
| -But there's a workaround, you can explicitly specify component's props like so: |
136 |
| -
|
137 |
| -`Bar.vue` |
138 |
| -
|
139 |
| -```vue |
140 |
| -<template> |
141 |
| - <Bar :a="'wrong'" /> |
142 |
| -</template> |
143 |
| -
|
144 |
| -<script setup lang="ts"> |
145 |
| -import { defineAsyncComponent, type DefineComponent } from 'vue' |
146 |
| -
|
147 |
| -interface Props { |
148 |
| - a: number |
149 |
| -} |
150 |
| -
|
151 |
| -const Bar = defineAsyncComponent<DefineComponent<Props>>( |
152 |
| - () => import('./Bar.vue') as any |
153 |
| -) |
154 |
| -defineProps<Props>() |
155 |
| -</script> |
156 |
| -``` |
157 |
| -
|
158 |
| -### Custom File Extensions |
159 |
| -
|
160 |
| -Syntax highlighting and intellisense can be applied to additional file extensions beyond just `vue`. This will need to be configured in three different places for full support. |
161 |
| -
|
162 |
| -In VS Code settings for the Volar extension add any additional extensions you need to `Additional Extensions`. Such as `ext`. |
163 |
| -
|
164 |
| -In your tsconfig.json file you will need to make sure your custom extension is included by TypeScript. If you have an include value for `./src/*.vue` then you would want to add an include for `./src/*.ext` as well. |
165 |
| -
|
166 |
| -```json |
167 |
| -"include": [ |
168 |
| - "./src/*.ts", |
169 |
| - "./src/*.vue", |
170 |
| - "./src/*.ext", |
171 |
| -] |
172 |
| -``` |
173 |
| -
|
174 |
| -Finally you need to make VS Code recognize your new extension and automatically associate it with the Vue language format. To do this you need to configure your File Associations setting to map `*.ext` to the language value `vue`. This can be done under Text Editor > Files, or with the key `files.associations`. |
175 |
| -
|
176 |
| - --> |
177 |
| - |
178 |
| -## Sponsors |
179 |
| - |
180 |
| -<!-- <table> |
181 |
| - <tbody> |
182 |
| - <tr> |
183 |
| - <td align="center" valign="middle" colspan="2"> |
184 |
| - <b>Special Sponsor</b> |
185 |
| - </td> |
186 |
| - </tr> |
187 |
| - <tr> |
188 |
| - <td align="center" valign="middle" colspan="2"> |
189 |
| - <a href="https://stackblitz.com/"> |
190 |
| - <img src="https://raw.githubusercontent.com/johnsoncodehk/sponsors/master/logos/StackBlitz.svg" height="80" /> |
191 |
| - </a> |
192 |
| - <p>Stay in the flow with instant dev experiences.<br>No more hours stashing/pulling/installing locally</p> |
193 |
| - <p><b> — just click, and start coding.</b></p> |
194 |
| - </td> |
195 |
| - </tr> |
196 |
| - <tr> |
197 |
| - <td align="center" valign="middle" colspan="2"> |
198 |
| - <b>Platinum Sponsors</b> |
199 |
| - </td> |
200 |
| - </tr> |
201 |
| - <tr> |
202 |
| - <td align="center" valign="middle" width="50%"> |
203 |
| - <a href="https://vuejs.org/"> |
204 |
| - <img src="https://raw.githubusercontent.com/johnsoncodehk/sponsors/master/logos/Vue.svg" height="80" /> |
205 |
| - </a> |
206 |
| - <p>An approachable, performant and versatile framework for building web user interfaces.</p> |
207 |
| - </td> |
208 |
| - <td align="center" valign="middle" width="50%"> |
209 |
| - <a href="https://astro.build/"> |
210 |
| - <img src="https://raw.githubusercontent.com/johnsoncodehk/sponsors/master/logos/Astro.svg" height="80" /> |
211 |
| - </a> |
212 |
| - <p>Astro powers the world's fastest websites, client-side web apps, dynamic API endpoints, and everything in-between.</p> |
213 |
| - </td> |
214 |
| - </tr> |
215 |
| - <tr> |
216 |
| - <td align="center" valign="middle"> |
217 |
| - <a href="https://www.jetbrains.com/"> |
218 |
| - <img src="https://raw.githubusercontent.com/johnsoncodehk/sponsors/master/logos/JetBrains.svg" height="80" /> |
219 |
| - </a> |
220 |
| - <p>Essential tools for software developers and teams.</p> |
221 |
| - </td> |
222 |
| - <td align="center" valign="middle"> |
223 |
| - </td> |
224 |
| - </tr> |
225 |
| - <tr> |
226 |
| - <td align="center" valign="middle" colspan="2"> |
227 |
| - <b>Silver Sponsors</b> |
228 |
| - </td> |
229 |
| - </tr> |
230 |
| - <tr> |
231 |
| - <td align="center" valign="middle"> |
232 |
| - <a href="https://www.prefect.io/"><img src="https://raw.githubusercontent.com/johnsoncodehk/sponsors/master/logos/Prefect.svg" height="50" /></a> |
233 |
| - </td> |
234 |
| - <td align="center" valign="middle"> |
235 |
| - <a href="https://www.techjobasia.com/"><img src="https://raw.githubusercontent.com/johnsoncodehk/sponsors/master/logos/TechJobAsia.svg" height="50" /></a> |
236 |
| - </td> |
237 |
| - </tr> |
238 |
| - </tbody> |
239 |
| -</table> --> |
240 |
| - |
241 | 14 | <p align="center">
|
242 | 15 | <a href="https://cdn.jsdelivr.net/gh/johnsoncodehk/sponsors/sponsors.svg">
|
243 | 16 | <img src="https://cdn.jsdelivr.net/gh/johnsoncodehk/sponsors/sponsors.png"/>
|
|
0 commit comments