💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] # Configuring VS Code for Vue Development ### Visual Studio Code is one of the most used code editors in the world right now. When you're such a popular editor, people build nice plugins. One of such plugins is an awesome tool that can help us Vue.js developers. - [Vetur](#vetur) - [Installing Vetur](#installing-vetur) - [Syntax highlighting](#syntax-highlighting) - [Snippets](#snippets) - [IntelliSense](#intellisense) - [Scaffolding](#scaffolding) - [Emmet](#emmet) - [Linting and error checking](#linting-and-error-checking) - [Code Formatting](#code-formatting) - - - - - - Visual Studio Code is one of the most used code editors in the world right now. Editors have, like many software products, a cycle. Once TextMate was the favorite by developers, then it was Sublime Text, now it's VS Code. The cool thing about being popular is that people dedicate a lot of time to building plugins for everything they imagine. One of such plugins is an awesome tool that can help us Vue.js developers. ## Vetur It's called **Vetur**, it's hugely popular, with more than 3 million downloads, and you can find it [on the Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=octref.vetur). ![](https://img.kancloud.cn/2a/54/2a5494a8b91eb01845a947b31b2ac624_1365x1041.png) ## Installing Vetur Clicking the Install button will trigger the installation panel in VS Code: ![](https://img.kancloud.cn/14/d7/14d77bde32504c110407aa7495d2aa55_1110x875.png) You can also simply open the Extensions in VS Code and search for "vetur": ![](https://img.kancloud.cn/c3/be/c3be3c98faaab08fbfb29d0d22bf82b6_1178x732.png) What does this extension provide? ## Syntax highlighting Vetur provides syntax highlighting for all your Vue source code files. Without Vetur, a .vue file will be displayed in this way by VS Code: ![](https://img.kancloud.cn/f8/5e/f85e2822da372798c86258b15ec839fb_1115x835.png) with Vetur installed: ![](https://img.kancloud.cn/0e/4f/0e4f4d039f98e2b47a7a51eb163606ea_1149x812.png) VS Code is able to recognize the type of code contained in a file from its extension. Using Single File Component, you mix different types of code inside the same file, from CSS to JavaScript to HTML. VS Code by default cannot recognize this kind of situation, and Vetur allows to provide syntax highlighting for each kind of code you use. Vetur enables support, among the others, for - HTML - CSS - JavaScript - Pug - Haml - SCSS - PostCSS - Sass - Stylus - TypeScript ## Snippets As with syntax highlighting, since VS Code cannot determine the kind of code contained in a part of a .vue file, it cannot provide the snippets we all love: pieces of code we can add to the file, provided by specialized plugins. Vetur provides VS Code the ability to use your favorite snippets in Single File Components. ## IntelliSense IntelliSense is also enabled bye Vetur, for each different language, with autocomplete: ![](https://img.kancloud.cn/9f/09/9f095b1f66c49d1cba67cf9fc2a71b89_1106x808.png) ## Scaffolding In addition to enabling custom snippets, Vetur provides its own set of snippets. Each one creates a specific tag (template, script or style) with its own language: - `scaffold` - `template with html` - `template with pug` - `script with JavaScript` - `script with TypeScript` - `style with CSS` - `style with CSS (scoped)` - `style with scss` - `style with scss (scoped)` - `style with less` - `style with less (scoped)` - `style with sass` - `style with sass (scoped)` - `style with postcss` - `style with postcss (scoped)` - `style with stylus` - `style with stylus (scoped)` If you type `scaffold`, you'll get a starter pack for a single-file component: ``` <template> </template> <script> export default { } </script> <style> </style> ``` the others are specific and create a single block of code. > Note: (scoped) means that it applies to the current component only ## Emmet [Emmet](../emmet), the popular HTML/CSS abbreviations engine, is supported by default. You can type one of the Emmet abbreviations and by pressing `tab` VS Code will automatically expand it to the HTML equivalent: ![](https://img.kancloud.cn/83/24/8324370a8274eedbaa5290751670dc38_889x603.gif) ## Linting and error checking Vetur integrates with [ESLint](../eslint), through the [VS Code ESLint plugin](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint). ![](https://img.kancloud.cn/fe/de/fede2d085d73b3e3f9677ea32d71a107_1106x762.png) ![](https://img.kancloud.cn/46/6e/466e692e42c3ee65db35794b22607234_1106x762.png) ## Code Formatting Vetur provides automatic support for code formatting, to format the whole file upon save (in combination with the `"editor.formatOnSave"` VS Code setting. You can choose to disable automatic formatting for some specific language by setting the `vetur.format.defaultFormatter.XXXXX` to `none` in the VS Code settings. To change one of those settings, just start searching for the string, and override what you want in the user settings (the right panel). Most of the languages supported use [Prettier](../prettier) for automatic formatting, a tool that's becoming an industry standard. Uses your Prettier configuration to determine your preferences.