前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >创建自己的Code Snippets在VSCode中

创建自己的Code Snippets在VSCode中

作者头像
前端知否
发布2020-03-23 17:52:33
2.7K0
发布2020-03-23 17:52:33
举报
文章被收录于专栏:前端知否

创建自己的Code Snippets在VSCode中

创建Vuejs文件模板代码片段

1. Go to Code → Preferences → User Snippets

2.弹出提示框,选择一个vue代码高亮插件,比如vue.js

3.VSCode会创建一个vue.json,开始自定义

代码语言:javascript
复制
* vue.json *
{
    "New File": {
        "prefix": "template",
        "body": [
            "<template>",
                "\t<div class='${name}'></div>",
            "</template>",
            "",
            "<script>",
                "\texport default {",
                    "\t\tname: '${name}'",
                "\t}",
            "</script>",
            "",
            "<style lang='sass'>",
                "\t.${name} {",
                "",  
                "\t}",
            "</style>"
        ]
    }
}

使用效果:

创建px2rem sass转换函数snippets

1. Go to Code → Preferences → User Snippets

2. 选择新建全局snippets file

3. VSCode会生成./vscode/px2rem.code-snippets,开始自定义:

代码语言:javascript
复制
{
  // Place your giftmall_app workspace 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:
  // "Print to console": {
  //  "scope": "javascript,typescript",
  //  "prefix": "log",
  //  "body": [
  //    "console.log('$1');",
  //    "$2"
  //  ],
  //  "description": "Log output to console"
  // }

  "px2rem": {
    "scope": "javascript,typescript,scss",
    "prefix": "prm",
    "body": [
      "pxToRem($1)"
    ],
    "description": "px to rem"
  }
}

4. 在 <stylelang=“scssscoped>中输入prm,就可以看到补全提示 prm->px2rem(参数值)

这里只是一个简单介绍,可以在平时工作中,去多多实践,减少一些无意义的体力活。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-06-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 前端知否 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 创建Vuejs文件模板代码片段
  • 创建px2rem sass转换函数snippets
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档