vue+ESLint 配置保存 自動(dòng)格式化代碼
1. 在.eslintrc.js 添加 vscode 終端啟動(dòng)服務(wù)
// 添加⾃定義規(guī)則 'prettier/prettier': [ // eslint校驗(yàn)不成功后,error或2則報(bào)錯(cuò),warn或1則警告,off或0則⽆提示 'error', { singleQuote: true, semi: false, //結(jié)束是否加分號(hào) printWidth: 160//每行最長字符 } ]
2.打開VS code 文件》首選項(xiàng)》設(shè)置》擴(kuò)展》ESLint》
// eslint格式化字符串 "editor.codeActionsOnSave": { "source.fixAll.eslint": true },
如果編譯 發(fā)現(xiàn)以下錯(cuò)誤
warning delete ·· (prettier/prettier) “error Delete ⏎ prettier/prettier” in .vue files
解決
在vuejs項(xiàng)目中,運(yùn)行如下命令解決:
npm run lint – --fix
如果還是沒行,就要在 vue.config.js
添加
// vue.config.js
// 舊 data: @import "~@/assets/scss/variables.scss"; // 新 prependData: @import ~@/assets/scss/variables.scss;
module.exports = { chainWebpack: config => { config.module .rule('eslint') .use('eslint-loader') .loader('eslint-loader') .tap(options => { options.fix = true return options }) } }
ERROR Failed to compile with 1 errors 1:06:43 error in ./src/App.vue?vue&type=style&index=0&lang=scss& Module build failed (from ./node_modules/sass-loader/dist/cjs.js): ValidationError: Invalid options object. Sass Loader has been initialized using an options object that does not match the API schema. - options has an unknown property 'prependdata'. These properties are valid: object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? } at validate (E:\VUE\ElementUI\myProject\vue-manage\node_modules\schema-utils\dist\validate.js:85:11) at Object.loader (E:\VUE\ElementUI\myProject\vue-manage\node_modules\sass-loader\dist\index.js:36:28) @ ./node_modules/vue-style-loader??ref--8-oneOf-1-0!./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=style&index=0&lang=scss& 4:14-416 14:3-18:5 15:22-424 @ ./src/App.vue?vue&type=style&index=0&lang=scss& @ ./src/App.vue @ ./src/main.js @ multi (webpack)-dev-server/client?http://192.168.3.30:3333/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
css laoder沒安裝安裝
npm install sass-loader --save-dev npm install node-sass --save-dev npm install css-loader style-loader --save-dev
總結(jié)
到此這篇關(guān)于vue+ESLint 配置保存 自動(dòng)格式化代碼的文章就介紹到這了,更多相關(guān)vue 配置保存 自動(dòng)格式化內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決antd datepicker 獲取時(shí)間默認(rèn)少8個(gè)小時(shí)的問題
這篇文章主要介紹了解決antd datepicker 獲取時(shí)間默認(rèn)少8個(gè)小時(shí)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-10-10解決Can''t find variable: SockJS vue項(xiàng)目的問題
這篇文章主要介紹了解決Can't find variable: SockJS vue項(xiàng)目的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09Vue+Electron打包桌面應(yīng)用(超詳細(xì)完整教程)
這篇文章主要介紹了Vue+Electron打包桌面應(yīng)用超詳細(xì)完整教程,在這大家要記住整個(gè)項(xiàng)目的json文件不能有注釋,及時(shí)沒報(bào)錯(cuò)也不行,否則運(yùn)行命令時(shí)還是有問題,具體細(xì)節(jié)問題參考下本文詳細(xì)講解2024-02-02Vue-Router進(jìn)階之滾動(dòng)行為詳解
本篇文章主要介紹了Vue-Router進(jìn)階之滾動(dòng)行為詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09Element-ui中元素滾動(dòng)時(shí)el-option超出元素區(qū)域的問題
這篇文章主要介紹了Element-ui中元素滾動(dòng)時(shí)el-option超出元素區(qū)域的問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-05-05