VSCode代码片段在Vue的template/script/style标签内无法正常工作。

huangapple go评论51阅读模式
英文:

VSCode Snippets not working inside Vue's template/script/style tags

问题

我是新手在 vscode 中,无法使代码片段在 Vue 文件中正常工作。它们在 /snippets/vue.json 中有效:

{
  "<template></template>": {
    "prefix": "template",
    "body": [
      "<template>$1</template>"
    ]
  }
}

这段代码在 vue base layer 中可行,但在 script/template/style 标签内无效。我尝试将它添加到 vue-injection-markdown.json 中,我认为它应该用于这种情况,但不起作用。我还创建了一个 vue-html.json 文件,并将 JSON 添加到其中,但这也不使代码片段起作用:

{
  "hello": {
    "prefix": "hello",
    "body": [
      "blub"
    ]
  } 
}

我已安装了以下两个插件:

  • Vue 语言特性 (Volar)
  • TypeScript Vue 插件 (Volar)

我做错了什么?

英文:

I'm new to vscode and can't get snippets to work properly inside of Vue files. They work in /snippets/vue.json:

{
  &quot;&lt;template&gt;&lt;/template&gt;&quot;: {
    &quot;prefix&quot;: &quot;template&quot;,
    &quot;body&quot;: [
      &quot;&lt;template&gt;$1&lt;/template&gt;&quot;
    ]
  }
}

This works, as long as it is written in the vue base layer but not inside script/template/style tags. I've tried adding it to vue-injection-markdown.json which I thought is used for exactly that but it doesn't work. I've also created a vue-html.json file and added the json there but it also doesn't make the snippets work:

{
  &quot;hello&quot;: {
    &quot;prefix&quot;: &quot;hello&quot;,
    &quot;body&quot;: [
      &quot;blub&quot;
    ]
  } 
}

I've installed both these plugins:

  • Vue Language Features (Volar)
  • TypeScript Vue Plugin (Volar)

What am I doing wrong?

答案1

得分: 2

  • javascript.json代码片段可在vue文件的<script>部分中使用。
  • html.json代码片段可在vue文件的<template>部分中使用。
  • vue.json代码片段只能在空的vue文件中使用(或至少在模板和脚本标签之外)。
  • global.json代码片段当然可以在任何地方使用。
英文:

It appears that:

  • javascript.json snippets work inside the &lt;script&gt; part of a vue file
  • html.json snippets work inside the &lt;template&gt; part of a vue file
  • vue.json snippets only work in an empty vue file (or at least, outside the template and script tags)
  • global.json snippets, of course, work everywhere

答案2

得分: 1

global.code-snippets 中定义,具有 html 范围,或者在 html.json 文件中定义。

英文:

Ok, it has to be defined either in global.code-snippets with a html scope or in the html.json file.

huangapple
  • 本文由 发表于 2023年2月8日 20:49:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75386046.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定