You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VSCode中为.vue文件内x-前缀标签设置绿色高亮?

实现VSCode中.vue文件x-前缀标签的绿色高亮

这个需求完全可行,你之前的配置不生效是因为scope指定错误——Vue文件里自定义标签的TextMate scope并非entity.name.tag.x-*,而是统一的entity.name.tag.vue,标签名属于token的文本内容,需要通过match规则来匹配前缀。

正确配置方案

将以下代码添加到你的VSCode设置JSON中:

"editor.tokenColorCustomizations": {
  "textMateRules": [
    {
      "language": "vue",
      "scope": "entity.name.tag.vue",
      "match": "<x-[\\w-]+",
      "settings": {
        "foreground": "#00ff00"
      }
    },
    {
      "language": "vue",
      "scope": "entity.name.tag.vue",
      "match": "</x-[\\w-]+",
      "settings": {
        "foreground": "#00ff00"
      }
    }
  ]
}

配置说明

  • language: "vue":限定规则仅对.vue文件生效
  • scope: "entity.name.tag.vue":定位Vue文件中的标签token
  • match:用正则匹配以x-开头的开标签(<x-xxx)和闭标签(</x-xxx)
  • foreground: "#00ff00":设置标签文本为绿色

生效步骤

  1. 按Ctrl+,打开设置面板,点击右上角的"打开设置(JSON)"按钮
  2. 将上述配置粘贴到JSON文件中并保存
  3. 按Ctrl+Shift+P执行"Reload Window"命令,配置即可生效

内容的提问来源于stack exchange,提问作者Danial Qsk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 18:01:18