VSCode在vue文件中设置手写笔样式格式

汤姆

我有一个如下所示的vue文件(不是很重要):

<template>
    //some pseudo-html
</template>

<script>
    //some javascript
</script>

<style lang='stylus'>
  @import '~variables'
  .card
    cursor pointer
    //some more stylus
</style>

我已经formatOnSave在VSCode中激活,我还安装了vetur和esLint。

当我在经典<style>标签内使用CSS代码时,我没有问题,但是当我使用时lang='stylus',ESLint仍在寻找CSS(出现类似的语法错误[css] { expected (css-lcurlyexpected))。

另外,当我使用手写笔时,保存时的自动格式化只是一团糟,它将所有内容都放在同一行上。保存后的结果:

<style lang='stylus'>
  @import '~variables'
  .card cursor pointer position relative padding //some more stylus
</style>

我试图更改vscode中的followinf设置:

vetur.format.defaultFormatter.css vetur.format.defaultFormatter.stylus

但无济于事。

我当前的设置:

{
  "workbench.colorTheme": "FlatUI Immersed",
  "workbench.iconTheme": "material-icon-theme",
  "files.trimTrailingWhitespace": true,
  "editor.insertSpaces": true,
  "editor.formatOnSave": true,
  "editor.detectIndentation": false,
  "editor.formatOnPaste": false,
  "editor.formatOnType": true,
  "editor.renderControlCharacters": true,
  "editor.renderWhitespace": "all",
  "editor.minimap.enabled": false,
  "editor.mouseWheelScrollSensitivity": 2,
  "editor.tabSize": 4,
  "editor.fontSize": 15,
  "window.zoomLevel": -1,
  "workbench.startupEditor": "newUntitledFile",
  "markdown.extension.preview.autoShowPreviewToSide": true,
  "markdown.preview.breaks": true,
}

和工作区特定的设置:

"settings": {
    "files.associations": {
      "*.vue": "html"
    },
    "editor.tabSize": 2,
    "editor.formatOnSave": true,
    // Defines space handling before function argument parentheses. Requires TypeScript >= 2.1.5.
    "typescript.format.insertSpaceBeforeFunctionParenthesis": true,
    // Defines space handling before function argument parentheses. Requires TypeScript >= 2.1.5.
    "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
    // Eslint options
    "eslint.enable": true,
    "eslint.options": {
      "extensions": [
        ".html",
        ".js",
        ".vue",
        ".jsx"
      ]
    },
    // An array of language ids which should be validated by ESLint
    "eslint.validate": [
      "javascript",
      "javascriptreact",
      {
        "language": "html",
        "autoFix": true
      }
    ],
    // Run the linter on save (onSave) or on type (onType)
    "eslint.run": "onSave",
    // Turns auto fix on save on or off.
    "eslint.autoFixOnSave": true,
  }

如果有人知道如何正确使用格式化程序和短绒棉布,这绝对是很棒的选择,但是经过2个小时的挖掘,我会坦诚地找到一种只为<style>标签禁用格式化程序和短绒布棉的方法

汤姆

因此,在进一步研究之后,我找到了解决方案:

删除这部分设置:

"files.associations": {
    "*.vue": "html"
 },

在这一部分替换htmlvue

"eslint.validate": [
   "javascript",
   "javascriptreact",
   {
     "language": "vue",
     "autoFix": true
   }
 ],

并添加:

"vetur.format.defaultFormatter.js": "none"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章