无法找出用户片段

发布于 2025-01-18 11:29:24 字数 714 浏览 2 评论 0原文

我试图在 VSCode 中创建另一个用户片段来自动化 document.querySelector 但每当我尝试时,它都会给我一个奇怪的错误,如下所示。我有另一个片段,效果很好,但这是我正在参加的在线课程向我展示的。我对 json 没有任何经验,所以我可能只是语法错误,但它与我之前的代码片段完全相同。

VSCode 屏幕截图

如果该链接不起作用,我将添加下面编写的代码。我收到的错误是在第一个花括号上,它显示 “文件结尾预期 .json”

感谢所有帮助:)

{                    // start of file and json object

// other snippets here

  
  "query selector": {
    "scope": "javascript",
    "prefix": "dq",
    "body": ["document.querySelector('$0')"],
    "description": "Select element from document"
  },

// other snippets here

}                    // end of json object

I am trying to make another user snippet in VSCode to automate the document.querySelector but whenever I try to it gives me a weird error shown below. I have another snippet that works just fine but that was shown to me by an online class I am taking. I don't have any experience with json so I may just be getting the syntax wrong but it is the exact same as my previous snippet.

VSCode screenshot

In case that link doesn't work I'll include the code written below. The error I am getting is on the very first curly brace and it says "end of file expected .json"

All help is appreciated :)

{                    // start of file and json object

// other snippets here

  
  "query selector": {
    "scope": "javascript",
    "prefix": "dq",
    "body": ["document.querySelector('$0')"],
    "description": "Select element from document"
  },

// other snippets here

}                    // end of json object

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白馒头 2025-01-25 11:29:24

您的JSON文件不正确。

您应该将对象从上面的JSON对象内部放置为“查询选择器”。

在第14行中的卷曲支架后添加逗号,然后在其中添加片段。从第17和24行删除外部卷曲括号。JSON

文件只是一个对象。

因此,您的摘要文件看起来像这样:

{
  "Print to console": {
    "prefix": "log",
    "body": [
      "console.log('$1');",
      "$2"
    ],
    "description": "Log output to console"
  },
  "query selector": {
    "scope": "javascript",
    "prefix": "dq",
    "body": [
      "document.querySelector('$0')"
    ],
    "description": "Select element from document"
  }
}

顺便说一句,我认为您不需要“ scope”键。

Your json file is incorrect.

You should place the object starting with the key “query selector” inside the json object above.

Add a comma after the curly brace in line 14 and add your snippet in there. Remove your outer curly braces from lines 17 and 24.

Json files are only one single object.

So your snippets file would look something like this:

{
  "Print to console": {
    "prefix": "log",
    "body": [
      "console.log('$1');",
      "$2"
    ],
    "description": "Log output to console"
  },
  "query selector": {
    "scope": "javascript",
    "prefix": "dq",
    "body": [
      "document.querySelector('$0')"
    ],
    "description": "Select element from document"
  }
}

By the way, I don't think you need the "scope" key.

夏花。依旧 2025-01-25 11:29:24

使用方括号开始 json 文件,并以方括号 [ ] 结束。

[
  {
  "query selector": {
  "scope": "javascript",
  "prefix": "dq",
  "body": 
  ["document.querySelector('$0')"],
  "description": "Select element from document"
                 }
  }
]

Use a square bracket to start a json file, and end with a square bracket [ ].

[
  {
  "query selector": {
  "scope": "javascript",
  "prefix": "dq",
  "body": 
  ["document.querySelector('$0')"],
  "description": "Select element from document"
                 }
  }
]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文