VSCODE配置vue模板

2020-04-24  本文已影响0人  彩云飘过

VSCode -vue项目,自定义.vue模版

1.安装vscode

vscode官网地址:

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

插件库中搜索Vetur,点击安装,安装完成之后点击重新加载

3.新建代码片段

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

4.删除不要的代码,粘入自己写的.vue模板

注意模板文件中想缩进的地方不可以使用TAB,必须替换成空格;

{
    "Print to console": {
        "prefix": "vue",
        "body": [
            "<!-- $1 -->",
            "<template>",
            "    <div class='$2'>$5</div>",
            "</template>",
            "",
            "<script>",
            " //api文档自动生成模板",
            " /**",
             "    * @api {get} /user/:id Request User information",
             "    * @apiName GetUser",
             "    * @apiGroup User",
             "    *",
             "    * @apiParam {Number} id Users unique ID.",
             "    *",
             "    * @apiSuccess {String} firstname Firstname of the User.",
             "    * @apiSuccess {String} lastname  Lastname of the User.",
             "    */",
            "    ",
            "export default {",
            "    ",
            "    components: {},",
            "    data() {",
            "        ",
            "        return {",
            "            ",
            "        };",
            "    },",
            "    //监听属性 类似于data概念",
            "    computed: {},",
            "    //监控data中的数据变化",
            "    watch: {},",
            "    ",
            "    methods: {",
            "        ",
            "    },",
            "    //生命周期 - 创建完成(可以访问当前this实例)",
            "    created() {",
            "        ",
            "    },",
            "    //生命周期 - 挂载完成(可以访问DOM元素)",
            "    mounted() {",
            "        ",
            "    },",
            "    beforeCreate() {}, ",
            "    beforeMount() {},",
            "    beforeUpdate() {}, ",
            "    updated() {}, ",
            "    beforeDestroy() {}, ",
            "    destroyed() {}, ",
            "    //如果页面有keep-alive缓存功能,这个函数会触发",
            "    activated() {}, ",
            "    }",
            "</script>",
            "<style lang='scss' scoped>",
            "    //@import url($3); 引入公共css类",
            "    $4",
            "</style>"
        ],
        "description": "Log output to console"
    }
}


5.重启vscode;

6.使用

上面代码中的 "prefix": "vue", 就是快捷键;保存好之后,新建.vue结尾的文件。这时新建的vue是空白文件。在此空白文件中输入vue + tab,会自动加载自定义的vue模板;

上一篇 下一篇

猜你喜欢

热点阅读