vscode创建快捷代码块,同时配置vue2和vue3的快捷代码块

文件——首选项——配置代码片段,弹出的搜索框内,输入   vue.json             

image

 之后在打开的vue.json中复制下面代码配置

{
    // 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:
    "vue3": {
        "prefix": "vue3",
        "body": [
            "<template>",
              "<div class='app-container'>",
                "",
             "</div>",
            "</template>",
            "<script setup>",

            "import {ref,reactive ,onMounted} from 'vue'",
            "onMounted(() => {",
            "",
            "});",

            "</script>",
            "<style scoped lang=''>",

            "</style>",
        ],
        "description": "vue3的快捷代码段"
    },
    "vue2": {
        "prefix": "vue2",
        "body": [
            "<template>",
              "<div class='app-container'>",
                "",
             "</div>",
            "</template>",
            "<script>",
            "export default{",
            "name:'',",
            "data(){",
            "return{",

            "",
            "}},",
            "created(){},",
            "mounted(){},",
            "methods:{},",
            "}",                
            "</script>",

            "<style scoped lang=''>",

            "</style>",
        ],
        "description": "vue2的快捷代码段"
    }
}

保存后,就可以在.vue文件中输入  vue2 回车快捷生成基础vue2代码段;输入vue3回车快捷生成基础vue3代码段。

 

posted @ 2025-10-23 16:10  山吹同学  阅读(6)  评论(0)    收藏  举报