mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Fix mountVueComponent
This commit is contained in:
parent
bf558b8bd0
commit
7e905fa7d7
@ -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
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user