ps-tcplayer
Version:
Tencent Cloud Player component with Vue2/Vue3 compatibility
32 lines (27 loc) • 1.01 kB
text/typescript
import tcplayer from './tcplayer.vue'
import { isVue2, isVue3, version } from 'vue-demi'
import TcPlayerComponent from './tccomponents'
// 扩展类型声明,添加install方法
interface TcPlayer {
name: string;
install: (Vue: any, options?: any) => void;
[key: string]: any;
}
// 将tcplayer转换为扩展后的类型,先转为unknown再转为TcPlayer
const tcplayerWithInstall = tcplayer as unknown as TcPlayer;
tcplayerWithInstall.install = function (Vue: any, options: any = {}) {
// 仅注册组件,不创建全局实例
Vue.component(tcplayerWithInstall.name, tcplayerWithInstall)
// 添加静态方法,在需要时创建实例
const prototype = isVue2 ? Vue.prototype : Vue.config.globalProperties
prototype.$tcPlayer = (config: any) => {
console.warn('使用 $tcPlayer 创建独立实例的方式已弃用,请直接使用组件标签')
return null
}
}
export {
version,
tcplayerWithInstall as tcplayer,
tcplayerWithInstall as default,
TcPlayerComponent
}