当我在Vue组件上执行格式化文档命令时。vue文件VSCode将所有单引号字符串替换为双引号字符串。

在我的具体情况下,该规则与要求单引号的electronic -vue lint配置冲突。

我没有安装更漂亮的扩展(没有更漂亮。singleQuote在我的设置)

如何定制VSCode来避免这种情况?


当前回答

对于JSX使用:

{"jsxSingleQuote": false}

其他回答

我使用的是typescript,对我来说,它在更漂亮的设置下检查“Tslint集成”标志得到了解决(在vscode首选项中):

正如@attdona所指出的,Vetur扩展包括了prettier。

虽然您可以根据接受的答案更改更漂亮的设置,但您也可以更改vue组件特定区域的格式化程序。

例如,在这里,我设置Vetur使用vcode -typescript格式化器,因为它默认使用单引号:

quote_type = single

将此添加到.editorconfig中

# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
quote_type = single

使用这个扩展。

https://marketplace.visualstudio.com/items?itemName=BriteSnow.vscode-toggle-quotes

cmd ' (ctrl '在win/Linux上)将在' ' '中循环

从vuejs/vetur发行页面https://github.com/vuejs/vetur/issues/986# 这个解决方案对我很有效。

在vcodes设置中。Json文件添加此条目

"vetur.format.defaultFormatterOptions": {
    "prettier": {
        "singleQuote": true
    }
},