当前位置:   article > 正文

解决vscode格式化代码html属性换行问题; ctrl+s格式化去除分号,格式化自动单引号;解决js格式化换行问题;mac上的settings.json完整配置_vscode 使用html格式化 js 不加两个空格

vscode 使用html格式化 js 不加两个空格

右键格式化文档或者ctrl + s保存 html不换行
在这里插入图片描述

1.安装两个插件①vetur ②Prettier - Code formatter

在这里插入图片描述
在这里插入图片描述
2.在vetur的settings.json中设置

在这里插入图片描述

配置ctrl+s触发格式化去除分号和单引号;配置格式化js换行;配置解决html属性换行
在这里插入图片描述

将最后一部分的设置,修改成上图即可

    // // 当保存代码的时候,会自动格式化
    "editor.formatOnSave": true,
    // 不添加分号
    "prettier.semi": false,
    // 使用单引号
    "prettier.singleQuote": true,
    // 解决Vue的属性换行问题
    "vetur.format.defaultFormatter.html": "js-beautify-html",
    "vetur.format.defaultFormatter.js": "vscode-typescript",//在配置了默认格式后 这个需要打开 否则js格式化会换行
    "vetur.format.defaultFormatterOptions": {

        "js-beautify-html": {
            "wrap_attributes": "auto"
        },
        "prettyhtml": {
            "printWidth": 1000,
            "singleQuote": false,
            "wrapAttributes": false,
            "sortAttributes": false
        }
    },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

3.如果右键格式化或者ctrl+s,没有触发效果,在配置一下格式化的默认方式:看图,选择Vetur为默认值。
在这里插入图片描述

4.这是我自己mac上的settings.json完整配置:

{
    "vetur.format.defaultFormatter.css": "prettier",
    "vetur.format.defaultFormatter.postcss": "prettier",
    "vetur.format.defaultFormatter.scss": "prettier",
    "vetur.format.defaultFormatter.less": "prettier",
    "vetur.format.defaultFormatter.stylus": "stylus-supremacy",
    "vetur.format.defaultFormatter.ts": "prettier",
    "editor.quickSuggestions": {
        "strings": true
    },
    // "workbench.iconTheme": "material-icon-theme",
    "git.autofetch": true,
    // vscode默认启用了根据文件类型自动设置tabsize的选项
    "editor.detectIndentation": true,
    // 重新设定tabsize
    "editor.tabSize": 2,
    // 添加 vue 支持
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        "vue",
        "html"
    ],
    // 显示 markdown 中英文切换时产生的特殊字符
    "editor.renderControlCharacters": true,
    //  #让函数(名)和后面的括号之间加个空格
    "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
    // #这个按用户自身习惯选择
    "workbench.iconTheme": "vscode-icons",
    "diffEditor.ignoreTrimWhitespace": true,
    "search.followSymlinks": false,
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    },
    "files.trimTrailingWhitespace": true,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "typescript.format.semicolons": "remove",
    "javascript.format.semicolons": "remove",
    "path-intellisense.mappings": {
        "@": "${workspaceRoot}/src"
    },
    "git.enableSmartCommit": true,
    "explorer.confirmDragAndDrop": false,
    "explorer.confirmDelete": false,
    "editor.accessibilitySupport": "off",
    "workbench.sideBar.location": "left",
    "tabnine.experimentalAutoImports": true,
    "gitlens.hovers.currentLine.over": "line",
    "html.format.enable": true,
    "search.exclude": {
        "**/node_modules": true,
        "**/bower_components": true,
        "**/dist": true
    },
    "files.associations": {
        "*.cjson": "jsonc",
        "*.wxss": "css",
        "*.wxs": "javascript"
    },
    "emmet.includeLanguages": {
        "wxml": "html"
    },
    "minapp-vscode.disableAutoConfig": true,
    "scssFormatter.singleQuote": true,
    "javascript.preferences.quoteStyle": "single",
    "[vue]": {
        "editor.defaultFormatter": "octref.vetur"
    },
    "files.autoSave": "afterDelay",
    // // 当保存代码的时候,会自动格式化
    "editor.formatOnSave": true,
    // 不添加分号
    "prettier.semi": false,
    // 使用单引号
    "prettier.singleQuote": true,
    // 解决Vue的属性换行问题
    // "eslint.enable": false, //如果你的项目开启了eslint和.eslintrc.js    那么设置false会关闭所有的eslint的检验(例如驼峰和变量是否声明和==)
    "vetur.format.defaultFormatter.html": "js-beautify-html",
    "vetur.format.defaultFormatter.js": "vscode-typescript", //在配置了默认格式后 这个需要打开 否则js格式化会换行
    "vetur.format.defaultFormatterOptions": {

        "prettier": {
            "semi": false,
            "singleQuote": true,
            "proseWrap": "always",
            "printWidth": 160,
            "trailingComma": "none"
        },
        "js-beautify-html": {
            "wrap_attributes": "auto"
        },
        "prettyhtml": {
            "printWidth": 1000,
            "singleQuote": true,
            "wrapAttributes": false,
            "sortAttributes": false
        }
    },
    "emmet.triggerExpansionOnTab": true,
    "terminal.integrated.defaultProfile.osx": "bash",
    "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "[json]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "[html]": {
        "editor.defaultFormatter": "HookyQR.beautify"
    },
    "security.workspace.trust.untrustedFiles": "open",
    "[javascript]": {
        "editor.defaultFormatter": "HookyQR.beautify"
    },
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/931688
推荐阅读
相关标签
  

闽ICP备14008679号