zoukankan      html  css  js  c++  java
  • vscode自定义片段

    1、Code -> 首选项 -> 用户片段

    2、填入代码片段文件的名称,然后回车

    3、在打开发文件中,写入代码片段的配置,如:

    {
        // Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
        // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
        // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 
        // used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
        // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 
        // Placeholders with the same ids are connected.
        // Example:
        "react_s_page": {
            "scope": "javascript,typescript,javascriptreact,typescriptreact",
            "prefix": "react_s_page",
            "body": [
                "/* 三方库 */",
                "import React from 'react'",
                "import { Link } from 'react-router-dom'",
                "",
                "/* redux 链接组件 */",
                "import concatRedux from '@utils/concatRedux'",
                "",
                "/* 引入 ts 公共 interface定义 */",
                "import {IConnectProps} from '@tsDefine/ICommon'",
                "",
                "/* 引入公共组件 */",
                "import Page from '@components/Page'",
                "",
                "/* 相对路径引入组件 */",
                "",
                "/* 引入样式 */",
                "import './index.scss'",
                "",
                "/* ts定义interface */",
                "interface IProps extends IConnectProps { }",
                "interface IState {}",
                "",
                "/* concatRedux 定下定义变量,避免js 的 @装饰器被 ts 检测然后报错 */",
                "const conncatRedux: Function = concatRedux;",
                "",
                "@conncatRedux('/$1', ['$2'], ['$3'])",
                "export default class Center extends React.Component<IProps, IState> {",
                "    componentDidMond(){",
                "",
                "    }",
                "    render() {",
                "        return (",
                "            <Page title='$4' className='page_$5'>",
                "",
                "            </Page>",
                "        )",
                "    }",
                "}",
            ],
            "description": "react 页面框架"
        }
    }

    4、然后就可以再定义的类型的文件中使用该代码片段,如我在 scope 中定义了 javascript,typescript,javascriptreact,typescriptreact 这四种类型的文件中可以使用 react_s_page 前缀插入该代码片段。

    官方文档:https://code.visualstudio.com/docs/editor/userdefinedsnippets

  • 相关阅读:
    Code First 迁移
    使用C#创建Windows服务 并发布Windows 服务
    线程(Thread,ThreadPool)、Task、Parallel
    用《捕鱼达人》去理解C#中的多线程
    Visual Studio提示“无法启动IIS Express Web服务器”的解决方法 调试闪退
    防cc攻击策略
    多线程和异步的异同和使用场景
    JQuery Checkbox 获取多选值 Checkbox选中个数
    C# 说说lock到底锁谁?(1)
    C# 说说lock到底锁谁?(2)
  • 原文地址:https://www.cnblogs.com/ayseeing/p/14239756.html
Copyright © 2011-2022 走看看