vscode自定义模板
在任何一个编译器中写代码,在编写常用的代码中,常常会存在一部分代码是重复输入的,尤其是vue中编写组件的时候。这里就以组件为例,创建出一套vue组件的模板文件,达到只要在编译器中输入了‘vue’就能够生成一套模板
- 打开控制台(两种方式)
a. 文件 -> 首选项 -> 用户片段
b.ctrl + shift + p唤出控制台后,输入snippets - 新建
随后在新生成的文件中输入
{
// Place your 全局 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"
// }
// Example:
"Print to console": {
"prefix": "vue",
"body": [
"<!-- 模块说明 -->",
"<template>",
" <div class=\"container\">",
"",
" </div>",
"</template>",
"",
"<script>",
"export default {",
" // 组件注册",
" components: {},",
" mixins: [],",
" props: [],",
" data () {",
" return {",
" }",
" },",
" computed: {},",
" watch: {},",
" methods: {},",
" // 生命周期 - 创建完成(访问当前this实例)",
" created () {},",
" // 生命周期 - 挂载完成(访问DOM元素)",
" mounted () {},",
" destroyed () {}",
"}",
"</script>",
"<style lang=\"less\" scoped>",
".container {",
"",
"}",
"</style>",
""
],
"description": "A vue file template"
}
}
- 这里的核心配置是
"prefix": "vue",
- 这样一个用户片段就创建好了,接下来就去试试吧