VS-Code用户代码片段 - 快捷生成代码

VS-Code用户代码片段 - 快捷生成代码

一.设置用户代码片段方法

1 - 首先打开VS-Code(Visual Studio Code)代码编辑器
VS-Code用户代码片段 -  快捷生成代码
2 - 找到设置图标并点击找到 - 用户代码片段 - 选项
VS-Code用户代码片段 -  快捷生成代码
3 - 点击图示对应选项
VS-Code用户代码片段 -  快捷生成代码

4 - 给你的专属代码片段起一个名字就可以开始编辑了
VS-Code用户代码片段 -  快捷生成代码
5 - 进来之后的样子,有一些参数也不难理解,都有注释
VS-Code用户代码片段 -  快捷生成代码

一.本人一些常用的代码片段(注:每个文件只能生成一个代码片段)

------把原有的全部删除,替换成下面的------

----------------------For循环(var声明方式)---------------------------

//for循环
//在js标签或者js文件中输入 - fori - 即可快捷生成代码片段
{
	// Place your snippets for javascript 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"
	// }
	"Print out fori": {
		"prefix": "fori",
		"body": [
			"for (var i =0;i<arr$1.length;i++){",
			" ",
			"}"
		],
		"description": "Output Loop 'fori'"
	}
}

----------------------For循环(let声明方式)---------------------------

//for循环
//在js标签或者js文件中输入 - forl - 即可快捷生成代码片段(注意:这个快捷键为forl)
{
	// Place your snippets for javascript 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"
	// }
	"Print out forl": {
		"prefix": "forl",
		"body": [
			"for (let i =0;i<arr$1.length;i++){",
			" ",
			"}"
		],
		"description": "Output Loop 'forl'"
	}
}

----------------------Vue的快捷键---------------------------

//快捷生成Vue代码片段
//在Vue文件中输入 - vue - 即可快捷生成代码片段(注意:英文、小写)
{
	// 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"
	// }
	"Print to console": {
    "prefix": "vue",  
    "body": [
      "<!-- $1 -->",
      "<template>",
      "  <div></div>",
      "</template>",
      "<script>",
			"export default {",
			"  props: {},",
			"  // 数据",
      "  data () {",
      "    return {}",
      "  },",
      "  // 生命周期 - 创建完成(访问当前this实例)",
      "  created () {},",
      "  // 生命周期 - 挂载完成(访问DOM元素)",
			"  mounted () {},",
			"  //  注册组件",
			"  components: {},",
			"  // 计算属性",
			"  computed: {},",
			"  // 方法合集",
			"  methods: {}",
      "}",
      "</script>",
      "<style lang='less'>",
      "/* @import url(); 引入css类 */",
      "</style>"
    ],
    "description": "Log output to console"
  }
}

看完这三个代码片段,其中的几个参数以及写法格式各位应该也都差不多了解了,就可以写自己需要的代码片段了。

上一篇:SpringBoot:5.springboot原理深入了解


下一篇:Codeforces-1485 F. Copy or Prefix Sum(DP)