Skip to content

Application

createApp()

Create a new Vue application instance. Use this to bootstrap your app.

ts
import { createApp } from 'vue';
import App from './App.vue';

const app = createApp(App);
app.mount('#app');

createSSRApp()

Create an app instance for server-side rendering (SSR). Use only in SSR setups.

ts
import { createSSRApp } from 'vue';
const app = createSSRApp(App);

mount()

Mounts the app instance to a DOM element.

ts
app.mount('#app');

unmount()

Unmounts the app instance and cleans up.

ts
app.unmount();

onUnmount()

Register a callback to run when the app is unmounted.

ts
import { onUnmounted } from 'vue';
onUnmounted(() => {
  // Cleanup code here
});

component()

Globally register a component.

ts
import MyButton from './MyButton.vue';
app.component('MyButton', MyButton);

directive()

Globally register a custom directive.

ts
app.directive('focus', {
  mounted(el) { el.focus(); }
});

use()

Install a plugin to the app.

ts
import MyPlugin from './plugins/my-plugin';
app.use(MyPlugin);

mixin()

Globally register a mixin (not recommended for most modern codebases).

ts
app.mixin({
  created() { console.log('Mixin!'); }
});

provide()

Provide a value globally for dependency injection.

ts
app.provide('key', 'value');

runWithContext()

Run a function within the app’s context (advanced, rarely used).

config

Access the app’s global config object for advanced configuration.

ts
app.config.errorHandler = (err) => { /* ... */ };

config.errorHandler

Custom global error handler for uncaught errors.

config.warnHandler

Custom handler for Vue warnings.

config.performance

Enable performance tracking (dev only).

config.compilerOptions

Advanced: customize template compiler options.

config.globalProperties

Add global properties accessible in all components.

ts
app.config.globalProperties.$http = myHttpClient;

config.optionMergeStrategies

Advanced: customize how options are merged.

config.idPrefix

Advanced: set SSR id prefix.

config.throwUnhandledErrorInProduction

Advanced: throw unhandled errors in production.

General

version

The current Vue version string.

ts
import { version } from 'vue';
console.log(version); // e.g. '3.4.0'

nextTick()

Defer a callback until after the next DOM update cycle.

ts
import { nextTick, ref } from 'vue';
const count = ref(0);
function inc() {
  count.value++;
  nextTick(() => {
    // DOM updated
  });
}

defineComponent()

Helps with type inference and better IDE support when defining components in TypeScript.

ts
import { defineComponent } from 'vue';
export default defineComponent({
  name: 'MyComponent',
  props: { msg: String },
  setup(props) {
    return () => <div>{props.msg}</div>;
  }
});

defineAsyncComponent()

Define a component that is loaded asynchronously (code-splitting).

ts
import { defineAsyncComponent } from 'vue';
const AsyncComp = defineAsyncComponent(() => import('./MyComponent.vue'));