UNPKG

tav-ui

Version:
1 lines 1.1 kB
{"version":3,"file":"with-install2.mjs","sources":["../../../../../packages/utils/with-install.ts"],"sourcesContent":["// 只是导入类型不是导入App的值\nimport type { App, Plugin } from 'vue'\n/**\n * 组件外部使用use时执行install,然后将组件注册为全局\n */\n\n// 类型必须导出否则生成不了.d.ts文件\nexport type SFCWithInstall<T> = T & Plugin\n\n/**\n * 定义一个withInstall方法处理以下组件类型问题\n * @param comp\n */\nexport const withInstall = <T>(comp: T) => {\n /**\n * 直接写comp.install = function(){} 的话会报错,因为comp下没有install方法\n * 所以从vue中引入Plugin类型,断言comp的类型为T&Plugin\n */\n ;(comp as SFCWithInstall<T>).install = function (app: App) {\n app.component((comp as any).name, comp)\n }\n return comp as SFCWithInstall<T>\n}\n"],"names":[],"mappings":"AAAY,MAAC,WAAW,GAAG,CAAC,IAAI,KAAK;AACrC,EAAE,CAAC;AACH,EAAE,IAAI,CAAC,OAAO,GAAG,SAAS,GAAG,EAAE;AAC/B,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACnC,GAAG,CAAC;AACJ,EAAE,OAAO,IAAI,CAAC;AACd;;;;"}