详解vscode中console.log的两种快速写法

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了详解vscode中console.log的两种快速写法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

(一)方法一:直接在script标签中提前定义,仅适用于该htML文件!

 let add = function(a,b){
 	return a + b;
 };
 console.LOG(add(20,300));
 
 const { ['log']:C } = console;
 C(add(20,300));

(二)方法二:按tab键快速生成console.log,且光标在()内部,再次按tab键光标自动跳转到下一行!
1、打开vscode编辑器,选择文件->首选项->用户片段,输入javascript.json并按下enter进入。
初次使用我们会发现一段被注释的代码如下:

{
	// 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"
	// }
}

2、解除Example以下的区间代码如下,其中部分参数意义如下:
①prefix:代码快捷键的入口,在这里我们根据个人习惯进行设置即可,如我设置的cl,那么配合tab健就可以直接生成console.log;
②body表示代码主体
$1表示生成代码快速生成后后光标首次出现的位置
$2写在"console.log('$1');"下面,表示在快速生成console.log()后,代码后会空出一行,并且再次按tab键时,光标会跳转到$2(空出的一行)的位置

{
	// 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": "cl",
		"body": [
			"console.log('$1');",
			"$2"
		],
		"description": "Log output to console"
	}
}

到此这篇关于vscode中console.log的两种快速写法的文章就介绍到这了,更多相关vscode console.log写法内容请搜索脚本宝典以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本宝典!

脚本宝典总结

以上是脚本宝典为你收集整理的详解vscode中console.log的两种快速写法全部内容,希望文章能够帮你解决详解vscode中console.log的两种快速写法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:vscodevscode