Vue项目模板 – Js规范
前言
如今前端使用Eslint插件来检测代码。本文则使用eslint和vscode工具实现前端代码自动检测和修复的功能。
本项目:
- 插件:eslint
安装eslint
安装命令:
npm install eslint --save-dev
复制代码
安装eslint插件eslint-plugin-vue,安装命令:
npm install eslint-plugin-vue --save-dev
复制代码
在根目录创建.eslinttr.js配置文件
module.exports = {
root: true,
parserOptions: {
sourceType: 'module',
},
parser: "vue-eslint-parser",
env: {
browser: true,
node: true,
es6: true,
},
"rules": {
// Override default options
"comma-dangle": [
"error",
"always",],
"indent": [
"error",
2,],
"no-cond-assign": [
"error",
"always",],
// Disable now, but enable in the future
"one-var": "off", // ["error", "never"]
// Disable
"init-declarations": "off",
"no-console": "off",
"no-inline-comments": "off",
},
};
复制代码
vscode配置文件settings.json新增配置项
配置中遇到vue文件报错,是由于.eslintrc.js文件没有设置parser: “vue-eslint-parser”
vscode安装插件Prettier – Code formatter
Prettier – Code formatter的作用是自动修复代码误区。
安装完后关闭重启vscdoe即可。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END