英文:
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:
{
  "<template></template>": {
    "prefix": "template",
    "body": [
      "<template>$1</template>"
    ]
  }
}
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:
{
  "hello": {
    "prefix": "hello",
    "body": [
      "blub"
    ]
  } 
}
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 
<script>part of a vue file - html.json snippets work inside the 
<template>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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论