聊聊vscode中如何配置vue文件自定义模板


本文摘自PHP中文网,作者青灯夜游,侵删。

本篇文章给大家介绍vscode中vue文件自定义模板的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

具体步骤

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

1.png

在输入框输入vue(如果要设置其他文件的模板,也可以输入其他文件)【推荐学习:《vscode教程》】

2、选择Vue(vue)

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

2.png

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

{

    // 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,按回车就可生成刚刚设置好的自定义模板

3.png

最终的模板:

4.png

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

阅读剩余部分

相关阅读 >>

vsCode怎么设置vue别名路径智能提示?

如何在vsCode上运行前端代码

vsCode插件不起作用怎么办

vsCode提示找不到node路径

win7系统无法打开vsCode

vsCode如何使代码颜色高亮

vsCode如何调试js

vsCode提示不见了怎么办

vsCode和vs2017区别

vsCode实时预览网页代码的设置方法

更多相关阅读请进入《vsCode》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...