应用类型
App
应用实例类型。
ts
declare class App {
static readonly version: string
readonly config: Required<AppConfig>
readonly rootView: View
readonly version: string
mount(container: HostContainer): this
unmount(): void
directive(name: string): Directive | undefined
directive(name: string, directive: Directive): this
provide(name: string | symbol, value: unknown): this
hasProvide(name: string | symbol): boolean
inject<T = any>(name: string | symbol, defaultValue?: T): T
use<T extends {}>(plugin: AppPlugin<T>, options?: T): this
}参考:应用实例 API
WebApp
Web 应用实例类型。
ts
declare class WebApp extends App {
override mount(container: Element | string): this
}SSRApp
SSR 应用实例类型。
ts
declare class SSRApp extends App {
override mount(
container: HostContainer | Element | string,
SSRContext?: Record<string, any>
): this
}AppConfig
应用配置类型。
ts
interface AppConfig {
errorHandler?: (error: unknown, info: ErrorInfo) => void
idPrefix?: string
}属性:
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
errorHandler | Function | 控制台输出 | 全局错误处理器 |
idPrefix | string | 'v' | 元素 ID 前缀 |
参考:app.config
AppPlugin
插件类型。
ts
type AppPlugin<T extends {} = {}> = AppObjectPlugin<T> | AppPluginInstall<T>说明:插件可以是函数或带有 install 方法的对象。
参考:app.use()
AppObjectPlugin
对象形式的插件。
ts
interface AppObjectPlugin<T extends {} = {}> {
install: AppPluginInstall<T>
}AppPluginInstall
插件安装函数类型。
ts
type AppPluginInstall<T extends {} = {}> =
| ((app: App, options?: T) => void) // 可选配置
| ((app: App) => void) // 无需配置
| ((app: App, options: T) => void) // 必填配置说明:支持三种签名形式,分别对应可选配置、无需配置和必填配置。
ErrorInfo
错误信息类型。
ts
interface ErrorInfo {
source: ErrorSource
instance: ComponentInstance | null
}