vscode中自定义vue模板

  • Post author:
  • Post category:vue


打开vscode后,在菜单栏File(文件) -> preperences(首选项) -> User Snippets(用户代码片段)弹框中输入vue选中vue.json

在这里插入图片描述

{
	"vue-template": {            
		"prefix": "vueTemp",            
		"body": [                
			"<template>",                
			"  <div>",                
			"",                
			" </div>",                
			"</template>",                
			"",                
			"<script>",                
			"export default {",                
			"  name: '$TM_FILENAME_BASE',",                
			"  data() { ",                
			"    return {",                
			"",                
			"    }",                
			"  },",                             
			"  components:{",               
				"  },",                   
			"  methods:{",       
			"",        
			"  },",
			"  mounted() {",               
			"",             
			"  },",            
			" }",        
			"</script>",      
				"",       
				"<style>",                               
			"</style>"               
		],         
		"description": "my vue template"  	
	}
}

注意,

$TM_FILENAME_BASE

代表当前文件的名称。更多vscode变量,参见:https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-syntax

新建’.vue’文件后,在文件空白第一行中输入vueTemp(即上面模板prefix定义的字段)

在这里插入图片描述

生成的默认代码如下:

在这里插入图片描述



版权声明:本文为joyce_lcy原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。