vs code 中 vue 文件的 template/script/style 标签显示为白色,是因默认主题未对 html 标签作用域(如 `entity.name.tag.html`)配置前景色;需通过 `editor.tokencolorcustomizations` 手动为当前主题定制标签颜色。
在 VS Code 中,Vue 单文件组件(.vue)的 、
✅ 解决方法:自定义 Token 颜色规则
? 关键注意点:
? 推荐配置示例(适配主流主题):
{
"editor.tokenColorCustomizations": {
"[One Dark Pro]": {
"textMateRules": [
{
"scope": "entity.name.tag.html",
"settings": {
"foreground": "#C792EA" // 紫罗兰色,清晰易读
}
}
]
},
"[Monokai]": {
"textMateRules": [
{
"scope": "entity.name.tag.html",
"settings": {
"foreground": "#F92672" // Monokai 经典粉红
}
}
]
}
}
}? 进阶提示:精准控制不同标签
VS Code 的 Vue 插件(如 Volar)配合语义化作用域,可实现更精细着色。例如:
此时可单独配置:
{
"scope": ["meta.tag.script.vue"],
"settings": { "foreground": "#FFB86C" }
},
{
"scope": ["meta.tag.template.vue"],
"settings": { "foreground": "#A4E579" }
}✅ 最后建议:安装 Volar(Vue 3 官方推荐语言服务器)并禁用旧版 Vetur,以获得完整且准确的 Vue 语法支持与作用域识别。
