VSCode新建vue文件自定義模板


在一個Vue的項目中,反復的新建.vue文件是一個必不可少的工序。本着科技讓人偷懶的原則,我們可以利用VSCode的snippet在.vue文件創建后能輕松地生成一套模板。

整個過程是輕松加愉快的,只需幾步即可。

具體步驟如下

1、選擇“文件 -> 首選項 -> 用戶代碼片段”,此時,會彈出一個搜索框,輸入vue

    選擇vue后,編輯器會自動打開一個名字為vue.json的文件

2、復制以下內容到這個文件中: 

{
    // 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"
    // }
    "Print to console": {
        "prefix": "vue",
        "body": [
            "<template>",
            "  <div id=\"app\">$0",
            "     <HelloWorld msg=\"Welcome\"/>",
            "  </div>",
            "</template>\n",
            "<script type=\"text/javascript\">",
            "import HelloWorld from './components/HelloWorld.vue'",
            "export default {",
            "  name: \"app\",",    
            "  data() {",
            "    return {\n",
            "    }",
            "  },",
            "  components: {",
            "    HelloWorld",
            "  }",
            "}",
            "</script>\n",
            "<style lang=\"stylus\" scoped>",
            "</style>",
            "$2"
        ],
        "description": "Log output to console"
    }
}

$0 表示生成代碼后光標的位置 ; 

prefix 表示生成對應預設代碼的命令(此處設置的vue)

  保存關閉文件;

3、新建.vue文件,輸入vue,按回車,頁面結構自動生成


4.最終

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM