1. 程式人生 > >VSCode新建vue文件自定義模板

VSCode新建vue文件自定義模板

.net play .json 代碼片段 javascrip 回車 round pos imp

在一個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.最終

技術分享圖片

VSCode新建vue文件自定義模板