1. 程式人生 > 其它 >VSCode - 快速生成vue模版

VSCode - 快速生成vue模版

1、安裝一個外掛,識別vue檔案
2、新建程式碼片段
Copy
管理-> 首選項 -> 使用者程式碼片段 -> (新建程式碼片段取名vue.json)
新建程式碼片段這塊可以直接往下找就能找到vscode上帶的vue.json

3、在vue.json裡寫下自己想要生成的vue模版
Copy
{
	// Place your snippets for vue 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": "vue",
		"body": [
			//"<!-- $1 -->",
			"<template>",
			"    <div>",
			"    </div>",
			"</template>",
			"",
			"<script>",
			"export default {",
			"    data() {",
			"        return {",
			"            ",
			"        }",
			"    },",
			"    //生命週期 - 建立完成(訪問當前this例項)",
			"    created() {",
			"        ",
			"    },",
			"    //生命週期 - 掛載完成(訪問DOM元素)",
			"    mounted() {",
			"        ",
			"    }",
			"}",
			"</script>",
			"<style scoped>",
			"/* @import url(); 引入css類 */",
			"$4",
			"</style>"
		],
		"description": "Log output to console"
	}
}
4、貼上以上程式碼複製到vue.json裡效果如下
Copy
此處說明一下:"prefix": "vue", 就是快捷鍵,(vue名稱可隨意修改)
新建vue檔案,輸入vue 按鍵盤的tab件生成vue模版