VS CODE自定义用户代码片段

628 阅读1分钟
  1. 依次点击:文件 -> 首选项 -> 用户代码片段

  2. 选择你要选择的文件类型

3. 以vue.json为🌰编辑xxx.json文件

json示例

{
    "Print to init vue template": {
		"prefix": "vt",
		"body": [
			"<template>",
      "  <div>",
      "    $0",
      "  </div>",
      "</template>",
      "",
      "<script>",
      "export default {",
      "  name: '$0',",
      "  data () {",
      "    return {",
      "    }",
      "  },",
      "  methods: {",
      "  },",
      "  mounted() {",
      "  }",
      "}",
      "</script>",
      "",
      "<style lang='less' scoped>",
      "",
      "</style>",
      ""
		],
		"description": "template with vue"
  }
}
{
  "Print to console": {
		"prefix": "log",
		"body": [
			"console.log('$1');",
			"$2"
		],
		"description": "Log output to console"
  },
  "Print to import": {
		"prefix": "import",
		"body": [
			"import $0 from '$0'",
		],
		"description": "import"
	},
  "Print to lss": {
		"prefix": "lss",
		"body": [
			"import lss from '@/services/LocalStorageService'",
		],
		"description": "lss"
  }
}

效果