VScode配置vue2用户代码片段
如默
撰写于 2019年 07月 25 日

介绍

如题,使用VScode新建一个文件的时候,比如 vue 文件,我们需要手动输入以下内容:

<template>
  <div>

  </div>
</template>

<script>
export default {
    name: "component_name",
    data() {
        return {

        }
    },
    created() {

    },

    mounted() {

    },

    methods() {

    },

    destroyed() {

    }
}
</script>

<style scoped>

</style>

每次新建都需要这么做,显得很麻烦,所以,我们需要配置一个模板

配置步骤

点击顶部菜单,文件-首选项-用户代码片段, 选择新建全局代码片段文件,随便输入一个文件名,比如vue

文件默认内容如下:

{
    // 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": "log",
    //  "body": [
    //      "console.log('$1');",
    //      "$2"
    //  ],
    //  "description": "Log output to console"
    // }
}

格式说明

配置文件需要三部分,prefix就是触发此模板文件的命令,body是模板内容,description就是描述信息

配置内容

以 vue 文件为例,配置模板内容如下:

{
    "Create vue template": {
        "prefix": "vue2",
        "body": [
            "<template>",
            "  <div>\n$0",
            "  </div>",
            "</template>\n",
            "<script>",
            "export default {",
            "    name: \"${1:component_name}\",",
            "    data() {",
            "        return {\n",
            "        }",
            "    },",
            "    created() {\n",
            "    },\n",
            "    mounted() {\n",
            "    },\n",
            "    methods() {\n",
            "    },\n",
            "    destroyed() {\n",
            "    }",
            "}",
            "</script>\n",
            "<style scoped>\n",
            "</style>"
        ],
        "description": "default vue template"
    }
}

注意:模板里不能使用tab制表符,否则会报错

此时,新建一个 vue 文件,输入vue2,按回车,会自动创建模板

其他格式代码参考 vue 语法即可

VScode配置vue2用户代码片段

温馨提示:

本文最后更新于2019年07月25日,已超过2035天没有更新,若内容或图片失效,请留言反馈。

介绍

如题,使用VScode新建一个文件的时候,比如 vue 文件,我们需要手动输入以下内容:

<template>
  <div>

  </div>
</template>

<script>
export default {
    name: "component_name",
    data() {
        return {

        }
    },
    created() {

    },

    mounted() {

    },

    methods() {

    },

    destroyed() {

    }
}
</script>

<style scoped>

</style>

每次新建都需要这么做,显得很麻烦,所以,我们需要配置一个模板

配置步骤

点击顶部菜单,文件-首选项-用户代码片段, 选择新建全局代码片段文件,随便输入一个文件名,比如vue

文件默认内容如下:

{
    // 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": "log",
    //  "body": [
    //      "console.log('$1');",
    //      "$2"
    //  ],
    //  "description": "Log output to console"
    // }
}

格式说明

配置文件需要三部分,prefix就是触发此模板文件的命令,body是模板内容,description就是描述信息

配置内容

以 vue 文件为例,配置模板内容如下:

{
    "Create vue template": {
        "prefix": "vue2",
        "body": [
            "<template>",
            "  <div>\n$0",
            "  </div>",
            "</template>\n",
            "<script>",
            "export default {",
            "    name: \"${1:component_name}\",",
            "    data() {",
            "        return {\n",
            "        }",
            "    },",
            "    created() {\n",
            "    },\n",
            "    mounted() {\n",
            "    },\n",
            "    methods() {\n",
            "    },\n",
            "    destroyed() {\n",
            "    }",
            "}",
            "</script>\n",
            "<style scoped>\n",
            "</style>"
        ],
        "description": "default vue template"
    }
}

注意:模板里不能使用tab制表符,否则会报错

此时,新建一个 vue 文件,输入vue2,按回车,会自动创建模板

其他格式代码参考 vue 语法即可


赞 (0)

猜您想看

  • 个人网站ICP备案指南

    网站想要在互联网上正常访问,是需要备案的,备案就是上户口,登记。

    2019年01月22日
  • MacOS配置homebrew

    前两天买的Mac mini到货了,正好需要配置环境,折腾了一下,特此记录。

    2023年03月02日
  • 漫步者M230无线蓝牙音箱入手体验

    之前用的是漫步者U20,是一个90块的小音箱,只有3W,用了四年,最近有刺啦声,加上后面的线感觉很乱,就换了M230蓝牙音箱。

    2022年10月25日
  • 迁移Git项目

    之前使用的是GitHub和Gitee,国外的访问速度太慢,国内的又各种限制,所以自己搭建了一个Gitea,用来存放代码,之前的仓库不想丢失log记录等信息,所以需要迁移,特此记录。

    2022年11月29日
  • 微信小程序canvasToTempFilePath:fail fail canvas is empty

    如题,最近在写一个小程序时,canvas报错,canvasToTempFilePath:fail fail canvas is empty,记录一下如何修复

    2024年09月10日
  • Python处理excel查找相同列内容并输出对应行数据

    前两天帮同学处理了一个excel,可以用Python实现,记录一下。

    2023年05月18日

评论区(暂无评论)

这里空空如也,快来评论吧~

我要评论

Vaptcha 初始化中...