当前位置:网站首页>Vscode creates its own code template

Vscode creates its own code template

2022-07-05 06:27:00 Heerey525

situation

I'll go back to react, Write jsx There's a bit more code , Each time you create a new component, you need to type it by hand or copy A template , It's inconvenient , Plan to match a set of templates , After that, you can use the shortcut key to directly generate .

Creating steps

1. The entrance opens

In one word :( top left corner ) file - Preferences - User code snippets
Entrance two : Here's the picture
 Insert picture description here

2. New code snippet

In order not to affect other code fragments , We choose New global code fragment file
 Insert picture description here
Fill in the file name you want to create , I intend to create jsx Code snippet of , So it was named jsx, Then click save
 Insert picture description here
The default is to take the example
 Insert picture description here

3. Write the configuration

prefix: Shortcut key
body: Code snippet for configuration \t Indent with space \n Refers to line feed
description: Description of code snippets
 Insert picture description here

This is the code. , You can also refer to , Configure a set of vue The template of

{
    
  "jsx_template": {
    
    "prefix": "jsx",
    "body": [
      "import React, { Component } from 'react';\n",
      "export default class xx extends Component {",
      "\trender() {",
      "\t\treturn <div>xx</div>;",
      "\t}",
      "}"
    ],
    "description": "jsx The template of "
  }
}

4. Use

Direct input jsx, enter
 Please add a picture description

Reference material :vsCode Create your own code template

原网站

版权声明
本文为[Heerey525]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050623068053.html