快速写代码小技巧 代码片段+我的常用代码片段

395 阅读1分钟

代码片段

作用

可以自定义自己常用的代码,在日后写代码时更方便快捷

使用

设置中打开

image.png

image.png
自定义代码片段的名字

image.png

image.png

举例

image.png

image.png

我的常用代码片段 ( 努力更新ing )

one

axios try catch

"async await":{
  "scope": "javascript,typescript",
  "prefix": "atc",
  "body": [
  "async $1($3) {",
      "try {",
      	"const res = await $2($3)",
        "console.log('$2', res)",
      	"$4",
      "} catch (error) {",
      	"console.log('$2',error)",
      "}",
  "}"
  ],
  "description": "tcaa"
}

two

提示框

"$confirm":{
  "scope": "javascript,typescript",
  "prefix": "$ctc",
  "body": [
     "this.confirm('Sure?', 'Tips', {",
        "confirmButtonText: 'YES',",
        "cancelButtonText: 'NO',",
        "type: 'warning'",
     "}).then(() => {",
         "$1",
     "}).catch(() => {",
	  "$2",
     "})"
  ],
  "description": "confirm then catch"
}

three

 ...