• 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

  • 相关阅读:
    玩转树莓派《二》——用python实现动画与多媒体
    pygame(一)
    玩转树莓派(一)
    pythonchallenge(七)
    springmvc定时器
    maven打包成第三方jar包且把pom依赖包打入进来
    mybatis之动态SQL
    黑马12期day01之html&css
    千万级数据表删除特定字断
    自动跳转
  • 原文地址:https://www.cnblogs.com/ayseeing/p/14239756.html
Copyright © 2020-2023  润新知