vscode中不用任何扩展自定义vue代码补全功能

163 阅读1分钟

需求背景

在使用vscode开发vue项目时,市面上的代码补全功能可能无法满足要求,我们需要自定义一些补全功能

教程

在vscode 界面按住ctr + shift + p调出控制台,在里面输入snippets,找到coniguer user snippets点开并输入vue进行编辑

test3.gif 输入如下内容并关闭即可

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

            "<template>",
            "$1",
            "</template>",
            "<script lang=\"ts\" setup>",
            "",
            "</script>",
            "<style lang=\"less\" scoped>",
            "</style>"
        ],
        "description": "Log output to console"
    }
}