vscode配置vue自定义模板

本文指导如何在VSCode中设置Vue自定义模板。通过点击设置中的用户代码片段,新建vue.json文件,并粘贴Vue3、TS和Less的代码模板,之后在编辑时输入'vue'即可触发模板。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.点击右下方设置里的用户代码片段

2.新建文件vue.json

 3.把以下代码复制进去 我下面的是vue3 ts less

{
    // Place your snippets for vue here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. 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": {
    //     "prefix": "log",
    //     "body": [
    //         "console.log('$1');",
    //         "$2"
    //     ],
    //     "description": "Log output to console"
    // }
    "vue-temp": {
        "prefix": "vue-tem",
        "body": [
            "<template>",
            "  <div class=\"\">",
            "",
            "",
            "",
            "",
            "  </div>",
            "</template>",
            "<script setup lang=\"ts\">",
            "",
            "",
            "",
            "",            
            "</script>",
            "<style lang=\"less\" scoped>",
            "",
            "",
            "",
            "",
            "</style>",
            ""
        ],
        "description": "快速创建vue3模板"
    }
}

4.在使用的时候 直接输入vue 就会出现这个模板了

 

 

### 配置 VSCodeVue3 默认项目模板 为了使 VSCode 更好地支持 Vue3 开发并配置默认模板,可以安装由 VUE 团队成员开发的插件 `Vue VSCode Snippets`[^1]。此工具提供了官方推荐的代码片段。 对于具体的模板配置,在 VSCode 中创建新的 Vue 文件时可以通过自定义代码片段实现自动化模板生成。具体方法是在用户代码片段中加入特定于 Vue3 的结构化模板: ```json { "demo": { "prefix": "v3", "body": [ "<template>", "\t", "</template>", "", "<script lang='ts'>", "import { defineComponent } from 'vue'", "export default defineComponent({", "\tsetup () {", "\t\t$0", "\t\treturn {", " ", "\t\t}", "\t}", "})", "</script>", "", "<style lang=\"less\" scoped>", "\t", "</style>" ], "description": "自定义的一个vue代码片段" } } ``` 上述 JSON 片段应放置在合适的代码片段文件内,比如命名为 `vue.json` 或者集成到已有的代码片段集合里[^3]。当完成这些设置之后,通过输入指定前缀(如这里的 `"v3"`),再按下 Tab 键或回车键就可以触发自动补全功能来快速构建一个新的 Vue 组件框架[^4]。 此外,还可以进一步简化这个过程,仅需输入简单的命令就能得到更精简版本的初始模板: ```json { "Print to console": { "prefix": "vue3", "body": [ "<template>", "", "</template>", "<script setup>", "", "</script>", "<style scoped lang='scss'>", "</style>", "$2" ], "description": "Log output to console" } } ``` 这样做的好处在于减少了不必要的样板代码量,使得开发者能够专注于业务逻辑编写而不是重复性的基础架构搭建工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值