VSCode 配置快捷html模板

1.安装vscode

官网地址:https://code.visualstudio.com/

2.安装一个插件,识别vue文件

插件库中搜索Vetur,安装

3.新建代码片段

文件-->首选项-->用户代码片段-->点击新建代码片段--取名xx.json 确定

File-->preferences-->User Snippets-->New Global Snippets file..-->取名xx.json-->Enter

4.删除不要的代码

5.粘入自己写的html模板

{
    // Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
    // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
    // is left empty or omitted, the snippet gets applied to all languages. 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": {
        // "scope": "javascript,typescript",
        "prefix": "v", //快捷键
        "body": [
            "<!DOCTYPE html>",
            "<html lang=\"en\">",
            "<head>",
            "<meta charset=\"UTF-8\">",
            "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
            "<title>title</title>",
            "<script src=\"https://cdn.jsdelivr.net/npm/vue/dist/vue.js\"></script>",
            "</head>",
            "<style>",
            "",
            "</style>",
            "<body>",
            "<div id=\"app\">",
            "{{msg}}",
            "</div>",
            "<script>",
            "const obj = {",
            "msg:'Hello world!',",
            "count:0,",
            "};",
            "const app = new Vue({",
            "el: '#app',",
            "data: obj,",
            "methods: {",
            "",
            "},",
            "});",
            "</script>",
            "</body>",
            "</html>",
        ],
        // "description": "Log output to console"
        "description": "vue html template"
    }
}
View Code

 

6.说明:

上面代码中的 "prefix": "v", 就是快捷键;名称可以自己更换

输入v按键盘的tab就行

 
 7.同理可生成自定义.vue文件模板
 
vue.json
{
    "Print to console": {
        "prefix": "vue",
        "body": [
            "<!-- $1 -->",
            "<template>",
            "<div class='$2'>$5</div>",
            "</template>",
            "",
            "<script>",
            "//这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)",
            "//例如:import 《组件名称》 from '《组件路径》';",
            "",
            "export default {",
            "//import引入的组件需要注入到对象中才能使用",
            "components: {},",
            "data() {",
            "//这里存放数据",
            "return {",
            "",
            "};",
            "},",
            "//监听属性 类似于data概念",
            "computed: {},",
            "//监控data中的数据变化",
            "watch: {},",
            "//方法集合",
            "methods: {",
            "",
            "},",
            "//生命周期 - 创建完成(可以访问当前this实例)",
            "created() {",
            "",
            "},",
            "//生命周期 - 挂载完成(可以访问DOM元素)",
            "mounted() {",
            "",
            "},",
            "beforeCreate() {}, //生命周期 - 创建之前",
            "beforeMount() {}, //生命周期 - 挂载之前",
            "beforeUpdate() {}, //生命周期 - 更新之前",
            "updated() {}, //生命周期 - 更新之后",
            "beforeDestroy() {}, //生命周期 - 销毁之前",
            "destroyed() {}, //生命周期 - 销毁完成",
            "activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发",
            "}",
            "</script>",
            "<style lang='scss' scoped>",
            "//@import url($3); 引入公共css类",
            "$4",
            "</style>"
        ],
        "description": "Log output to console"
    }
}
View Code

输入vue按键盘的tab就行

参考:https://www.jianshu.com/p/8610215a8a84

 
 
posted @ 2020-05-20 15:29  凌137  阅读(1567)  评论(0编辑  收藏  举报