配置用户代码片段(vue.code-snippets)

本文分享了如何在VSCode中配置用于Vue3和TypeScript开发的代码片段,提升开发效率。用户可以直接复制提供的vue.code-snippets文件内容到.vscode目录,根据个人需求调整prefix。

为了提高开发效率,很多时候会在vscode中配置好一些常用的代码片段,省时省力还显示你很NB。
以下是基于vue3跟Ts个人的配置,分享出来(代码直接复制到vue.code-snippets文件即可使用,可根据个人情况进行修改prefix)。

{
  "new page": {
    "prefix": "<vue-basic",
    "body": [
      "<template>",
      "</template>",
      "<script lang=\"ts\">",
      "import { ref, defineComponent } from 'vue'",
      "export default defineComponent({",
      "  name: '$1',",
      "  setup() {",
      "    return {",
      "    }",
      "  },",
      "})",
      "</script>",
      "<style lang=\"less\">",
      "</style>",
      ""
    ],
    "description": "new component"
  },
  "template": {
    "scope": "vue",
    "prefix": "template",
    "body": [
        "<template>",
        "  $1",
        "</template>"
    ],
    "description": "Create <template> block"
  },
  "script": {
      "scope": "vue",
      "prefix": "script",
      "body": [
          "<script lang=\"ts\">",
          "import { defineComponent } from 'vue';",
          "",
          "export default defineComponent({",
          "  $2",
          "});",
          "</script>"
      ],
      "description": "Create <script> block"
  },
  "script setup": {
      "scope": "vue",
      "prefix": "script setup",
      "body": [
          "<script lang=\"ts\" setup>",
          "defineProps<{ $1 }>();",
          "</script>"
      ],
      "description": "Create <script setup> + <script> blocks"
  },
  "style": {
      "scope": "vue",
      "prefix": "style",
      "body": [
          "<style lang=\"less\" scoped>",
          "$1",
          "</style>"
      ],
      "description": "Create <style> block"
  },
  "v-for": {
      "scope": "html",
      "prefix": "v-for",
      "body": [
          "<template v-for=\"$1 in $2\">",
          "  $3",
          "</template>"
      ],
      "description": "Create html tag with v-for"
  },
  "v-if": {
      "scope": "html",
      "prefix": "v-if",
      "body": [
          "<template v-if=\"$1\">",
          "  $2",
          "</template>"
      ],
      "description": "Create html tag with v-if"
  },
  "v-else-if": {
      "scope": "html",
      "prefix": "v-else-if",
      "body": [
          "<template v-else-if=\"$1\">",
          "  $2",
          "</template>"
      ],
      "description": "Create html tag with v-else-if"
  },
  "v-else": {
      "scope": "html",
      "prefix": "v-else",
      "body": [
          "<template v-else>",
          "  $2",
          "</template>"
      ],
      "description": "Create html tag with v-else"
  }
}

说明:vue.code-snippets文件放在**.vscode**里面
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值