VSCode新建vue文件自定義模板

在一個Vue的項目中,反覆的新建.vue文件是一個必不可少的工序。本着科技讓人偷懶的原則,咱們能夠利用VSCode的snippet在.vue文件建立後能輕鬆地生成一套模板。javascript

整個過程是輕鬆加愉快的,只需幾步便可。vue

具體步驟以下

一、選擇「文件 -> 首選項 -> 用戶代碼片斷」,此時,會彈出一個搜索框,輸入vuejava

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

二、複製如下內容到這個文件中: app

{
    // 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)spa

  保存關閉文件;3d

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


4.最終component

 

相關文章
相關標籤/搜索