vscode 自定义全局代码片段
一、创建新的自定义用户代码片段
文件 - 首选项 - 用户片段
选择新代码片段
命名文件
二、写自定义代码片段JS
{// 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 or typescript 等,不填就是通配符 * 全局使用"prefix": "df", //输入 df 按回车,就可以自动输入 "body" 配置项中的内容"body": [".then(response => {$1},error => {})"], //自定义代码片段,一行写完格式化一下就行,若要多行,使用 "我是第一行内容","我是第二行内容" 这个格式"description": "promise.then()" //自定义代码片段的说明提示文字}}
三、演示Gif
追加
如上Gif
图所示,在使用promise
的风格request
请求时,经常需要.then
才能获取数据,输入自定义代码片段前缀df
按回车,就可以自动输入.then(response => {},error => {})
,炒鸡方便
如果觉得《vscode 自定义全局代码片段》对你有帮助,请点赞、收藏,并留下你的观点哦!