app.use重写 发表于 2022-11-16 | 分类于 Hooks MyUse.ts 123456789101112131415161718import type { App } from 'vue'import { app } from '../main'interface Use { install: (app: App, ...options: any[]) => void}const installList = new Set()export function MyUse<T extends Use>(plugin: T, ...options: any[]) { if (installList.has(plugin)) { console.log('has been registered'); } else { plugin.install(app, ...options) installList.add(plugin) }} main.ts 12345export const app = createApp(App)import { MyUse } from './hooks/MyUse'MyUse(Loading)