Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使vscode更优雅地支持vue #15

Open
ly2011 opened this issue Apr 9, 2018 · 0 comments
Open

使vscode更优雅地支持vue #15

ly2011 opened this issue Apr 9, 2018 · 0 comments
Labels

Comments

@ly2011
Copy link
Owner

ly2011 commented Apr 9, 2018

使vscode更优雅地支持vue

第一步,要支持 vue 文件的基本语法高亮

  • 1、安装 vetur 插件

Ctrl + P 然后输入 ext install vetur 然后回车点安装即可

这时可以打开一个vue文件试试,注意下右下角状态栏是否正确识别为 vue 类型:

如果被识别为 text 或 html ,则记得要点击切换下。

  • 2、配置 vetur 插件

安装完 vetur 后还需要加上这样一段配置下:

"emmet.syntaxProfiles": {
  "vue-html": "html",
  "vue": "html"
}

第二步,要支持 vue 文件的 ESLint

  • 1、安装 eslint 插件

Ctrl + P 然后输入 ext install eslint 然后回车点安装即可。

  • 2、配置 eslint

ESLint 不是安装后就可以用的,还需要一些环境和配置:

首先,需要全局的 ESLint , 如果没有安装可以使用 npm install -g eslint 来安装。

其次,vue文件是类 HTML 的文件,为了支持对 vue 文件的 ESLint ,需要 eslint-plugin-html 这个插件。可以使用 npm install -g eslint-plugin-html 来安装

接着,安装了 HTML 插件后,还需要在 vscode 中配置下 ESLint:

"eslint.validate": [
    "javascript",
    "javascriptreact",
    "html",
    "vue"
],
"eslint.options": {
    "plugins": ["html"]
},

最后,别忘了在项目根目录下创建 .eslintrc.json , 如果还没创建,还可以使用下面快捷命令来创建:

这样一来 vue 中写的 js 代码也能正确地被 lint 了。

@ly2011 ly2011 added the 工具 label Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant