VSCode自定义html模板,自动导入Vue框架,附带示例程序

编辑html.json文件

        在使用Vue时,每次都需要手动使用script标签来导入Vue框架,非常的麻烦,所有我们可以用html模板来自动生成

        Vscode可以通过编辑html.json文件来实现自定义模板,下面是具体步骤

  1.         打开VS code
  2.         点击Manage(左下角齿轮图标)
  3.         点击User Snippets
  4.         搜索html,选中html.json

        输入如下代码:

{

    // Place your snippets for html 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"

    // }

    "html template":{

        "prefix": "hv", //使用模版的快捷键

        "body": [ //模版的内容都定义在body中

            "<!DOCTYPE html>",

            "<html lang=\"en\">",

            "<head>",

            "\t<meta charset=\"UTF-8\">",

            "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",

            "<title>Document</title>",

            "</head>",

            "<body>",

            "\t<!--导入Vue在线包-->",

            "\t<script src=\"https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js\"></script>",

            "\n\t<div id=\"app\">\n\t\t$0\n\t</div>\n", //$0 鼠标停留的位置

            "\t<script>",

            "\t\tconst app=new Vue({",

            "\t\t\tel:'#app',",

            "\t\t\tdata:{\n\n\t\t\t},",

            "\t\t\tmethods:{\n",

            "\t\t\t}",

            "\t\t})",

            "\t</script>",

            "</body>",

            "</html>"

        ],

        "description": "Vue框架模版" //模版的描述

    }

}

       注意:前面注释是html.json自带的,这里引入的框架是通过网址引入的的,网址可能因为时间等不确定因素失效,请前往vue2的官网中获取。在"安装"中即可找到在线引入的方法。   

转义序列

代码中的\t、\n参考C语言中的转义字符,特别注意" "字符串中带有"的需要用\"来表示。

        这些转义序列字符不一定在所有的显示设备上都起作用。例如,换页符和垂直制表符在PC屏幕上会生成奇怪的符号,光标不会移动。只有将其输出到打印机上时才会产生前面描述的效果。

使用模板

 现在来试试,在一个空的html文件里输入hv

可以看到这里显示了VScode预显示模板,按下回车或tab键即可

  • 18
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值