项目中有些代码模块是固定的,如下面的代码所示,为了不重复写这些相同的代码,我们可以使用快键键一键生成模板。
流程:
中文:首选项-> 用户代码片段 -> 输入框中输入vue,找到vue.json文件(没有vue.json,选vue也可)-> 定义所需的代码段
英文:Preferences->Configure Snippets-> 输入框中输入vue,找到vue.json文件(没有vue.json,选vue也可)-> 定义所需的代码段
定义代码段:
定义了两段代码模版,vue3,vue32
其中$1,$2,$3是鼠标焦点位置,点击tab可以切换到$2,$3的位置。
{ "vue3 template": { "prefix": "vue3", //键入该值,按tab快捷产生 "body": [ "<script setup lang=\"ts\">", "$3", "</script>", "", "<template>", " $1", "</template>", "", "<style scoped lang=\"scss\">", "$2", "</style>", ], "description": "Log output to vue3 template" }, "vue3 template2": { "prefix": "vue32", //键入该值,按tab快捷产生 "body": [ "<script setup lang=\"ts\">", "$3", "console.log('');", "</script>", "", "<template>", " $1", "</template>", "", "<style scoped lang=\"scss\">", "$2", "</style>", ], "description": "Log output to vue3 template2" }, }
复制
在vue文件中输入vue3,vue32,回车即可
生成vue3模版
生成vue32模版