Fix mountVueComponent

This commit is contained in:
timongh 2022-03-20 21:59:45 +08:00
parent bf558b8bd0
commit 7e905fa7d7
2 changed files with 11 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { VueConstructor } from 'vue'
import { Component } from 'vue'
export type Executable<ReturnType = void> = () => ReturnType | Promise<ReturnType>
export type ExecutableWithParameter<Parameters extends any[] = never[], ReturnType = void> = (
@ -7,7 +7,7 @@ export type ExecutableWithParameter<Parameters extends any[] = never[], ReturnTy
export type TestPattern = (string | RegExp)[]
export type ArrayContent<T> = T extends Array<infer R> ? R : T
export type VueModule = VueConstructor | { default: VueConstructor }
export type VueModule = Component | { default: Component }
export type I18nDescription = string | { 'zh-CN': string; [key: string]: string }
export type WithName = {
name: string

View File

@ -98,10 +98,15 @@ export const matchUrlPattern = (pattern: string | RegExp) => (
* @param module Vue组件模块对象
* @param target ,
*/
export const mountVueComponent = <T>(module: VueModule, target?: Element | string) => {
const instance = new Vue('default' in module ? module.default : module)
// const instance = new Vue({ render: h => h('default' in module ? module.default : module) })
return instance.$mount(target) as Vue & T
export const mountVueComponent = <T>(
module: VueModule,
target?: Element | string,
): Vue & T => {
const options = 'default' in module ? module.default : module
const getInstance = (o: any) => (
o.functional ? new (Vue.extend(o))() : new Vue(o)
)
return getInstance(options).$mount(target) as Vue & T
}
/** 是否处于其他网站的内嵌播放器中 */
export const isEmbeddedPlayer = () => window.location.host === 'player.bilibili.com' || document.URL.startsWith('https://www.bilibili.com/html/player.html')