选择菜单里的 文件 > 首选项 > 用户代码片段
vscode模板
{
"Print to conaole":{
"prefix": "v-ts", //在新建立的页面中输入C++就会有智能提示,Tab就自动生成好了
"body": [
"",
" ", //这个头文件可以删除,我为了使用方便就加了
" ",
" ",
" ", //空行
"", //标准命名空间
"",
""
],
"description": "vue3 template." //用户输入后智能提示的内容(你可以用中文写“生成C++模板”)
}
}
结果
useCurrentInstance.ts
import { ComponentInternalInstance, getCurrentInstance } from 'vue'
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default function useCurrentInstance() {
const { appContext } = getCurrentInstance() as ComponentInternalInstance
const proxy = appContext.config.globalProperties
return {
proxy
}
}