Vue.js 3 runtime core library providing foundational APIs for building custom renderers and managing reactive component systems
—
Vue's component system provides a declarative way to build reactive user interfaces through reusable components with lifecycle management, props, and composition API integration.
Define components using the composition API or options API with full TypeScript support.
/**
* Defines a component with setup function
* @param setup - Setup function with props and context
* @param options - Additional component options
* @returns Component definition
*/
function defineComponent<Props, RawBindings = object>(
setup: (props: Props, ctx: SetupContext) => RawBindings | RenderFunction
): DefineComponent<Props, RawBindings>;
/**
* Defines a component with options object
* @param options - Component options including data, methods, computed, etc.
* @returns Component definition
*/
function defineComponent<
Props = {},
RawBindings = {},
D = {},
C extends ComputedOptions = {},
M extends MethodOptions = {}
>(options: ComponentOptionsWithoutProps<Props, RawBindings, D, C, M>): DefineComponent<Props, RawBindings, D, C, M>;
/**
* Defines an async component with loader function
* @param loader - Function that returns a Promise resolving to component
* @returns Async component
*/
function defineAsyncComponent<T extends Component = Component>(
loader: AsyncComponentLoader<T>
): T;
/**
* Defines an async component with options
* @param options - Async component configuration
* @returns Async component
*/
function defineAsyncComponent<T extends Component = Component>(
options: AsyncComponentOptions<T>
): T;Usage Examples:
import { defineComponent, defineAsyncComponent, ref, computed } from "@vue/runtime-core";
// Composition API component
const MyComponent = defineComponent({
props: {
message: String,
count: Number
},
setup(props, { emit, expose }) {
const localCount = ref(props.count || 0);
const doubled = computed(() => localCount.value * 2);
const increment = () => {
localCount.value++;
emit('update:count', localCount.value);
};
// Expose methods to parent
expose({ increment });
return {
localCount,
doubled,
increment
};
}
});
// Options API component
const OptionsComponent = defineComponent({
props: ['title'],
data() {
return {
count: 0
};
},
computed: {
uppercaseTitle() {
return this.title?.toUpperCase();
}
},
methods: {
increment() {
this.count++;
}
}
});
// Async component with loader
const AsyncComp = defineAsyncComponent(() => import('./HeavyComponent.vue'));
// Async component with options
const AsyncCompWithOptions = defineAsyncComponent({
loader: () => import('./HeavyComponent.vue'),
loadingComponent: LoadingComponent,
errorComponent: ErrorComponent,
delay: 200,
timeout: 3000
});Access and manage component instances with their internal state and lifecycle.
/**
* Gets the current component instance (only available during setup)
* @returns Current component instance or null
*/
function getCurrentInstance(): ComponentInternalInstance | null;
/**
* Registers a runtime compiler for template compilation
* @param compile - Compiler function
*/
function registerRuntimeCompiler(compile: any): void;
/**
* Checks if running in runtime-only mode
* @returns True if runtime-only, false if full build
*/
function isRuntimeOnly(): boolean;Usage Examples:
import { defineComponent, getCurrentInstance, onMounted } from "@vue/runtime-core";
const MyComponent = defineComponent({
setup() {
const instance = getCurrentInstance();
onMounted(() => {
if (instance) {
console.log('Component UID:', instance.uid);
console.log('Parent:', instance.parent);
console.log('VNode:', instance.vnode);
}
});
return {};
}
});Access component context and utility functions within the setup function.
/**
* Gets setup context slots (only available during setup)
* @returns Component slots object
*/
function useSlots(): Slots;
/**
* Gets setup context attrs (only available during setup)
* @returns Component attrs object
*/
function useAttrs(): Data;Usage Examples:
import { defineComponent, useSlots, useAttrs } from "@vue/runtime-core";
const WrapperComponent = defineComponent({
setup() {
const slots = useSlots();
const attrs = useAttrs();
console.log('Available slots:', Object.keys(slots));
console.log('Component attrs:', attrs);
return {
slots,
attrs
};
}
});Compile-time macros for <script setup> syntax (runtime representations for typing).
/**
* Declares component props (compile-time macro)
* @returns Props type
*/
function defineProps<T = {}>(): T;
/**
* Declares component emits (compile-time macro)
* @returns Emit function
*/
function defineEmits<T extends EmitsOptions = {}>(): EmitFn<T>;
/**
* Declares exposed properties and methods (compile-time macro)
* @param exposed - Object containing exposed properties
*/
function defineExpose<T extends Record<string, any>>(exposed?: T): void;
/**
* Declares additional component options (compile-time macro)
* @param options - Component options
*/
function defineOptions<T extends Partial<ComponentOptions>>(options?: T): void;
/**
* Declares slot types (compile-time macro)
* @returns Slots type
*/
function defineSlots<S extends Record<string, any> = Record<string, any>>(): S;
/**
* Declares v-model props (compile-time macro)
* @returns Model ref
*/
function defineModel<T>(): ModelRef<T>;
/**
* Provides default values for props (compile-time macro)
* @param props - Props object
* @param defaults - Default values
* @returns Props with defaults applied
*/
function withDefaults<T>(props: T, defaults: Partial<T>): T;Usage Examples:
import { defineComponent, defineProps, defineEmits, defineExpose } from "@vue/runtime-core";
// These are typically used in <script setup> but shown here for API reference
const ScriptSetupComponent = defineComponent({
setup() {
// These macros are compile-time only in actual <script setup>
const props = defineProps<{
message: string;
count?: number;
}>();
const emit = defineEmits<{
'update:count': [value: number];
'click': [event: MouseEvent];
}>();
const increment = () => {
const newCount = (props.count || 0) + 1;
emit('update:count', newCount);
};
defineExpose({
increment
});
return {
increment
};
}
});Internal helper functions for advanced component composition patterns.
/**
* Merges prop defaults with props (internal)
* @param props - Props object
* @param defaults - Default values
* @returns Merged props
*/
function mergeDefaults<T>(props: T, defaults: Partial<T>): T;
/**
* Merges model declarations (internal)
* @param props - Props object
* @param models - Model declarations
* @returns Merged props with models
*/
function mergeModels<T>(props: T, models: Record<string, any>): T;
/**
* Creates a rest proxy for props destructuring (internal)
* @param props - Props object
* @param excludedKeys - Keys to exclude from rest
* @returns Rest proxy
*/
function createPropsRestProxy<T extends Record<string, any>>(
props: T,
excludedKeys: string[]
): Omit<T, keyof typeof excludedKeys>;
/**
* Preserves instance context over async/await (internal)
* @param getAwaitable - Function returning awaitable
* @returns Awaitable with preserved context
*/
function withAsyncContext<T>(getAwaitable: () => T): T;interface ComponentInternalInstance {
uid: number;
vnode: VNode;
type: ConcreteComponent;
parent: ComponentInternalInstance | null;
root: ComponentInternalInstance;
appContext: AppContext;
// State
data: Data;
props: Data;
attrs: Data;
slots: InternalSlots;
refs: Data;
emit: EmitFn;
// Lifecycle
isMounted: boolean;
isUnmounted: boolean;
isDeactivated: boolean;
// Setup
setupState: Data;
setupContext: SetupContext | null;
// Render
render: InternalRenderFunction | null;
proxy: ComponentPublicInstance | null;
exposed: Record<string, any> | null;
// Suspense
suspense: SuspenseBoundary | null;
suspenseId: number;
// SSR
ssrContext: object | null;
}
interface SetupContext<E = EmitsOptions> {
attrs: Data;
slots: Slots;
emit: EmitFn<E>;
expose: (exposed?: Record<string, any>) => void;
}
type DefineComponent<
PropsOrPropOptions = {},
RawBindings = {},
D = {},
C extends ComputedOptions = ComputedOptions,
M extends MethodOptions = MethodOptions,
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = {},
EE extends string = string,
PP = PublicProps,
Props = Readonly<PropsOrPropOptions>,
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
> = ComponentPublicInstanceConstructor<
CreateComponentPublicInstance<
Props,
RawBindings,
D,
C,
M,
Mixin,
Extends,
E,
PP & Props,
Defaults,
true
> &
Props
> &
ComponentOptionsBase<Props, RawBindings, D, C, M, Mixin, Extends, E, EE, Defaults> &
PP;
interface AsyncComponentLoader<T = any> {
(): Promise<T>;
}
interface AsyncComponentOptions<T = any> {
loader: AsyncComponentLoader<T>;
loadingComponent?: Component;
errorComponent?: Component;
delay?: number;
timeout?: number;
suspensible?: boolean;
onError?: (
error: Error,
retry: () => void,
fail: () => void,
attempts: number
) => any;
}
interface ComponentOptions<
V = {},
D = {},
C extends ComputedOptions = {},
M extends MethodOptions = {},
E extends EmitsOptions = {},
Props = {}
> {
// Data
data?: (this: V & Props) => D;
props?: ComponentPropsOptions<Props>;
propsData?: Partial<Props>; // For 2.x compat only
// DOM
el?: string | Element;
template?: string;
render?: Function;
renderTracked?: DebuggerHook;
renderTriggered?: DebuggerHook;
// Lifecycle
beforeCreate?(): void;
created?(): void;
beforeMount?(): void;
mounted?(): void;
beforeUpdate?(): void;
updated?(): void;
activated?(): void;
deactivated?(): void;
beforeDestroy?(): void;
beforeUnmount?(): void;
destroyed?(): void;
unmounted?(): void;
renderError?: (e: Error, instance: ComponentPublicInstance, info: string) => void;
errorCaptured?: ErrorCapturedHook;
// Assets
directives?: Record<string, Directive>;
components?: Record<string, Component>;
// Composition
mixins?: ComponentOptionsMixin[];
extends?: ComponentOptionsMixin;
// Other
name?: string;
inheritAttrs?: boolean;
emits?: E;
expose?: string[];
serverPrefetch?(): void | Promise<any>;
}
interface ModelRef<T> extends Ref<T> {
readonly [ModelRefMarkerSymbol]: true;
}
type EmitFn<
Options = ObjectEmitsOptions,
Event extends keyof Options = keyof Options
> = Options extends Array<infer V>
? (event: V, ...args: any[]) => void
: {} extends Options // if the emit is empty object (usually the default value for emit) should be converted to function
? (event: string, ...args: any[]) => void
: UnionToIntersection<
{
[key in Event]: Options[key] extends (...args: infer Args) => any
? (event: key, ...args: Args) => void
: (event: key, ...args: any[]) => void;
}[Event]
>;
interface Slots {
[name: string]: Slot | undefined;
}
type Slot<T extends any = any> = (
...args: IfAny<T, any[], [T] | (T extends undefined ? [] : never)>
) => VNode[];Install with Tessl CLI
npx tessl i tessl/npm-vue--runtime-core