首页 > 其他分享 >vue3 vite 脚手架生成项目 prettier 自动格式化失败 vscode插件 Vue - Official 解决方案

vue3 vite 脚手架生成项目 prettier 自动格式化失败 vscode插件 Vue - Official 解决方案

时间:2024-05-31 14:57:12浏览次数:23  
标签:插件 Vue 格式化 vscode vue prettier vue3 true eslint

vue3 vite 脚手架生成项目 prettier 自动格式化失败 vscode插件 Vue - Official 解决方案

问题

以前写的都是vue2的项目,自动格式化都用的vetur,都设置好了。
现在新弄了个vue3的项目,脚手架起的vite vue3,搞个代码格式化,发现prettier没好事。

解决思路

格式化一共俩工具

  1. eslint
  2. prettier

格式化的时候选择用eslint格式化,然后将prettier的配置放到eslint里面就ok了

vue3项目的单独配置

  1. 配置保存自动格式化
    settings.json(工作区)
{
  "editor.codeActionsOnSave": {
    // "source.fixAll.eslint": "always"
  },
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  // "prettier.singleAttributePerLine": true,
  "[vue]": {
    "editor.defaultFormatter": "dbaeumer.vscode-eslint"
  }
}

重点思路1:

codeActionsOnSave里面什么都不要执行,然后formatOnSave自动格式化,vue文件指定eslint格式化

重点思路2:

这里调整prettier的时候,注意,有时候不好使,重启vscode
.eslintrc.cjs

/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
	root: true,
	extends: [
		"plugin:vue/vue3-essential",
		"eslint:recommended",
		"@vue/eslint-config-prettier/skip-formatting",
	],
	parserOptions: {
		ecmaVersion: "latest",
	},
	rules: {
		/**关注代码美观度 */
		"prettier/prettier": [
			"warn",
			{
				bracketSameLine: true,
				bracketSpacing: true,
				semi: false,
				experimentalTernaries: false,
				singleQuote: false,
				jsxSingleQuote: false,
				quoteProps: "as-needed",
				trailingComma: "all",
				singleAttributePerLine: true,
				htmlWhitespaceSensitivity: "css",
				vueIndentScriptAndStyle: false,
				proseWrap: "preserve",
				insertPragma: false,
				printWidth: 80,
				requirePragma: false,
				tabWidth: 2,
				useTabs: true,
				embeddedLanguageFormatting: "off",
				cursorOffset: -1,
			},
		],
		/**Eslint关注规范 */
		"vue/multi-word-component-names": [
			"warn",
			{
				ignores: ["index"], //vue组件名称多单词组成 忽略index.vue
			},
		],
		"vue/no-setup-props-destructure": ["off"], //关闭props解构的校验(props解构丢失响应式)
		"no-undef": "error", //添加未定义变量错误提示  off
	},
};

reference

prettier 官方定制定制
https://prettier.io/playground/

Eslint配合Prettier完成代码风格配置
https://blog.csdn.net/qq_37899792/article/details/132752647

标签:插件,Vue,格式化,vscode,vue,prettier,vue3,true,eslint
From: https://www.cnblogs.com/pengchenggang/p/18224581

相关文章

  • 265:vue+openlayers 一次性清除所有控件(亲测好用)
    作者:还是大剑师兰特,曾为美国某知名大学计算机专业研究生,现为GIS领域高级前端工程师;CSDN知名博主,深耕openlayers、leaflet、mapbox、cesium,canvas,echarts等技术开发,欢迎加微信(gis-dajianshi),一起交流。查看本专栏目录-本文是第265个示例文章目录一、示......
  • vue 导出xlsx (报错./cptable in ./node modules/xlsx-style/dist/cpexcel.js)
    安装 xlsx 和  xlsx-stylesrc下创建文件夹utils, utils文件夹下创建index.js文件,index.js文件内容如下:*CreatedbyAnqion16/11/18.*//***Parsethetimetostring*@param{(Object|string|number)}time*@param{string}cFormat*@returns{stri......
  • VUE卖座网
      免费获取方式↓↓↓   项目介绍033:项目名:卖座网技术栈:VUE网址:http://localhost:8080/功能(前端数据都为静态假数据,仅展示,实现动态需自行搭建后端)电影正在上映即将上映影院全城app订票最近去过资讯我的 二、技术栈 所有场景都支持适合零基础小......
  • vue小白商城
      免费获取方式↓↓↓   项目介绍034:npminstallnpmrunservenpmrunbuild主要功能小白商城首页我的消息收藏夹购物车卖家中心联乐客服关于我们 二、技术栈 所有场景都支持适合零基础小白练手和实战;适合二次开发;项目图片概览:以上是对本项目的界面......
  • 基于springboot+vue的音乐网站
      项目介绍025:前台:http://localhost:8081/#/后台:http://localhost:8080/#/前台账号:wang123后台账号:admin1项目功能音乐播放MV播放用户登录注册用户信息编辑、头像修改歌曲、歌单搜索歌单打分歌单、歌曲评论歌单列表、歌手列表分页显示歌词同步显示音乐收藏......
  • 校园周边美食探索及分享平台,基于 SpringBoot+Vue+MySQL 开发的前后端分离的校园周边美
    目录一.前言二.功能模块2.1. 前台首页功能模块2.2. 用户功能模块2.3. 管理员功能模块三.部分代码实现四.源码下载一.前言美食一直是与人们日常生活息息相关的产业。传统的电话订餐或者到店消费已经不能适应市场发展的需求。随着网络的迅速崛起,互联网日益成......
  • WebStorm + Vite3.0 + Vue2.7 前端断点调试
    WebStorm+Vite3.0+Vue2.7前端断点调试目录WebStorm+Vite3.0+Vue2.7前端断点调试使用工具版本1、添加调试配置2、启动调试问题参考使用工具版本WebStorm2023.2、NodeJsv16.20.2、Vue2.7.7、Vite3.0.2、JavaScript1、添加调试配置右上角选择编辑配置.新......
  • 在Vue3中,集成VueQuill Rich Text Editor for Vue 3
    官网地址:https://vueup.github.io/vue-quill/github:https://github.com/vueup/vue-quill没有中文包,胜在简单,步骤,按官网说明安装:npminstall@vueup/vue-quill@latest--save#ORyarnadd@vueup/vue-quill@latest在项目的\src\components\路径下建立 QuillEdito......
  • vue2如何父组件 对象 双向绑定子组件
    对于Vue2,你不能直接用v-model绑定对象,但可以通过在子组件内部处理valueprop的变化并触发input事件来模拟这一行为。父组件A1<template>2<ComponentBv-model="item"prop-names="addressId,date,startTime,endTime"/>3<ComponentCv-model="item"prop-names=&qu......
  • 基于springboot实习管理系统的设计与实现vue(源码+lw+部署文档+讲解等)
    前言......