• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

谈谈vscode配置vue文件自定义模板

武飞扬头像
PHP中文网
帮助243

具体步骤

1、文件 --> 首选项 --> 用户片段

学新通技术网

2、选择Vue(vue)

编辑器自动打开了一份vue.json文件

学新通技术网

3、根据自己的需求,在"Print to console"里如何自己的模板要求,例子如下:

{
    // 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"
    // }
    "vue": {
        "prefix": "vue",
        "body": [
            "<template>",
            "  $0",
            "</template>\n",
            "<script>\n",
            "export default {",
            "  name: '',\n",
            "  components: {},\n",
            "  data() {",
            "    return {}",
            "  },\n",
            "  created() {},\n",
            "  methods: {},\n",
            "}\n",
            "</script>\n",
            "<style scoped>",
            "</style>",
        ],
        "description": "This is a simple vue template"
    }
}

prefix: 表示生成自定义模板的命令(vue) body:自定义模板,每行为数组里的一个元素 $0: 表示生成模板后光标的所在位置 description: 自定义模板的描述

4、保存vue.json 文件

5、新建一个vue文件,输入vue,按回车就可生成刚刚设置好的自定义模板

学新通技术网

最终的模板:

学新通技术网

那问题来了如果我要设置多个自定义模板呢?

这个也很简单,只有在刚设置好的vue.json里,在写多一个模板就行了,如下:

{
    "vue": {
        "prefix": "vue",
        "body": [
            "<template>",
            "  $0",
            "</template>\n",
            "<script>\n",
            "export default {",
            "  name: '',\n",
            "  components: {},\n",
            "  data() {",
            "    return {}",
            "  },\n",
            "  created() {},\n",
            "  methods: {},\n",
            "}\n",
            "</script>\n",
            "<style scoped>",
            "</style>",
        ],
        "description": "This is a simple vue template"
    },

    "vue2": {
        "prefix": "vue2",
        "body": [
            "<template>",
            "  $0",
            "</template>\n",
            "<script>\n",
            "export default {",
            "  name: '',\n",
            "  props: {},\n",
            "  data() {",
            "    return {}",
            "  },\n",
            "  created() {},\n",
            "  methods: {},\n",
            "}\n",
            "</script>\n",
            "<style scoped>",
            "</style>",
        ],
        "description": "This is a simple vue template"
    },
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanfkjcj
系列文章
更多 icon
同类精品
更多 icon
继续加载