VS Code如果自定义代码片段

224 阅读1分钟

使用方法:设置-用户代码片段-选择要触发的文件类型-编写json模板,如下所示

// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.  
// 每个代码片段都是一个键值对,key为名称,这没有输出个不重要,value为一个对象,prefix为触发的快捷键,  
// body为模板,每一行用引号包裹,description为快捷键的描述  

{

"Print to console": {
    "prefix": "vue",
    "body": [
		"<template>",
		"$0",
		"</template>",
		"<script>",
		"export default {",
		"  name: 'componentName',",
		"  props: {",
		"    propName:{",
		"       type:String,",
		"       default:''",
		"   }",
		"},",
		"  components: {},",
		"  data () {",
		"   return {",
		"     tableData: [],",
		"     formData: {},",
		"    };",
		"  },",
		"  computed: {},",
		"  methods: {",
		"    handleSearch(){",
		"",
		"       },",
		"    },",
		"  created () {",
		"  },",
		"};",
		"</script> ",
		"<style scoped lang='less'>",
		"",
		"</style>",
    ],
    "description": "vue基础模板"
},
"名称不重要": {
    "prefix": "haha",
    "body": [
		"<temp333late>",
		"$0",
		"</temp333late>",
    ],
    "description": "vue基础模板"
}

}