YouTip LogoYouTip

Vue3 Global Api

Vueerrors occur in the application. Global API \\\\n\\\\n Vueerrors occur in the application. Global API | \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n \\\\n
No.API & DescriptionExample
Create for Server-Side Rendering (SSR)createApp() Create a Vue application Example, typically used for client-side rendering.const app = createApp(App)
Set a global error handler, triggered when uncaughtcreateSSRApp() Create for Server-Side Rendering (SSR)'s Vue Application Example.const app = createSSRApp(App)
errors occur in the application.app.mount() Set Vue Application Example mounted to specified's DOM On the element.app.mount('#app')
compilation behavior.app.unmount() Unmount the Vue application Example.app.unmount()
Configure the template compilerapp.onUnmount() Register during unmount'sCallback function.app.onUnmount(() => { console.log('App is being unmounted') })
Set a global warning handler to handleapp.component() Register global components, making them available anywhere.app.component('MyComponent', MyComponent)
Define component option merging strategies, controlling how componentapp.directive() Register global directives, allowing the creation of custom directives.app.directive('focus', { mounted(el) { el.focus() } })
callback functions.app.use() Install plugins, which can provide additional features for the application.app.use(SomePlugin)
Global configuration.app.mixin() Register global mixins, providing shared data or methods to all components.app.mixin({ methods: { globalMethod() { ... } } })
Create for Server-Side Rendering (SSR)0app.provide() Provide dependencies to the entire application, sharing data across components.app.provide('key', 'some value')
Create for Server-Side Rendering (SSR)Create for Server-Side Rendering (SSR)app.runWithContext()Run a function in the Vue app context, allowing access to context data.app.runWithContext(() => { console.log('Running inside app context') })
Create for Server-Side Rendering (SSR)Set a global error handler, triggered when uncaughtapp.version Get Vue current'sVersion number.console.log(app.version)
Create for Server-Side Rendering (SSR)errors occur in the application.app.config Get and set Application Example'sGlobal configuration.app.config.globalProperties.$myProperty = 'value'
Create for Server-Side Rendering (SSR)compilation behavior.app.config.errorHandler Set global error handling function, triggered when uncaught errors occur in the application'sTriggered when errors occur.app.config.errorHandler = (err, vm, info) => { console.error(err) }
Create for Server-Side Rendering (SSR)Configure the template compilerapp.config.warnHandler Set global warning handling function, handle warnings in the application'sWarning messages.app.config.warnHandler = (msg, vm, trace) => { console.warn(msg) }
Create for Server-Side Rendering (SSR)Set a global warning handler to handleapp.config.performance Enable performance monitoring, providing rendering performance data.app.config.performance = true
Create for Server-Side Rendering (SSR)Define component option merging strategies, controlling how componentapp.config.compilerOptions Configure template compiler'sOptions, control template'sCompilation behavior.app.config.compilerOptions.delimiters = ['[[', ']]']
Create for Server-Side Rendering (SSR)callback functions.app.config.globalProperties Set global properties accessible by all components in the application.app.config.globalProperties.$myGlobalProperty = 'value'
Create for Server-Side Rendering (SSR)Global configuration.app.config.optionMergeStrategies Define component options merge strategy, control how to merge components'sOptions.app.config.optionMergeStrategies.methods = (parent, child) => { return { ...parent, ...child } }
Set a global error handler, triggered when uncaught0app.config.idPrefixSet the prefix for Vue instance IDs, default is "vue-".app.config.idPrefix = 'myApp-'
Set a global error handler, triggered when uncaughtCreate for Server-Side Rendering (SSR)app.config.throwUnhandledErrorInProduction Control whether unhandled errors are thrown in production environment'sErrors.app.config.throwUnhandledErrorInProduction = false
Set a global error handler, triggered when uncaughtSet a global error handler, triggered when uncaughtversion Get Vue current'sVersion number.console.log(Vue.version)
Set a global error handler, triggered when uncaughterrors occur in the application.nextTick()Execute delayed callback after DOM update is complete, used for handling asynchronous DOM updates.nextTick(() => { console.log('DOM updated') })
Set a global error handler, triggered when uncaughtcompilation behavior.defineComponent() Used to define components, providing type inference and more concise'sSyntax.export default defineComponent({ name: 'MyComponent' })
Set a global error handler, triggered when uncaughtConfigure the template compilerdefineAsyncComponent() Define async components that are lazily loaded when needed.const AsyncComponent = defineAsyncComponent(() => import('./AsyncComponent.vue'))
\\\\n\\\\n Application Instance API\\\\n Create for Server-Side Rendering (SSR). `createApp()`\\\\n

Function: Creates a Vue application instance.

\\\\n

Usage: `createApp(rootComponent, rootProps)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `rootComponent`: The root component.
  • \\\\n
  • `rootProps` (optional): Props to pass to the root component.
  • \\\\n
\\\\n Example
import { createApp } from 'vue';\\\\nimport App from './App.vue';\\\\nconst app = createApp(App);\\\\n
Set a global error handler, triggered when uncaught. `createSSRApp()`\\\\n

Function: Creates a Vue application instance that supports Server-Side Rendering (SSR).

\\\\n

Usage: `createSSRApp(rootComponent, rootProps)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `rootComponent`: The root component.
  • \\\\n
  • `rootProps` (optional): Props passed to the root component.
  • \\\\n
\\\\nExample
import { createSSRApp } from 'vue';\\\\nimport App from './App.vue';\\\\nconst app = createSSRApp(App);\\\\n
errors occur in the application.. `app.mount()`\\\\n

Function: Mounts the application to a DOM element.

\\\\n

Usage: `app.mount(container)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `container`: DOM element or selector string.
  • \\\\n
\\\\nExample
app.mount('#app');\\\\n
compilation behavior.. `app.unmount()`\\\\n

Function: Unmount the application instance.

\\\\n

Usage: `app.unmount()`

\\\\nExample
app.unmount();\\\\n
Configure the template compiler. `app.onUnmount()`\\\\n

Function: Registers a callback function that is called when the application is unmounted.

\\\\n

Usage: `app.onUnmount(callback)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `callback`: The function to be called when unmounted.
  • \\\\n
\\\\nExample
app.onUnmount(() => {\\\\n    console.log('App unmounted');\\\\n});\\\\n
Set a global warning handler to handle. `app.component()`\\\\n

Function: Register or retrieve a global component.

\\\\n

Usage:

\\\\n
    \\\\n
  • Register: `app.component(name, component)
  • \\\\n
  • Retrieve: `app.component(name)
  • \\\\n
\\\\n

Parameters:

\\\\n
    \\\\n
  • `name`: The component name.
  • \\\\n
  • `component`: The component definition.
  • \\\\n
\\\\nExample
app.component('MyComponent', {\\\\n    template: '
My Component
'\\\\n});\\\\n
Define component option merging strategies, controlling how component. `app.directive()`\\\\n

Function: Register or retrieve a global directive.

\\\\n

Usage:

\\\\n
    \\\\n
  • Register: `app.directive(name, directive)
  • \\\\n
  • Retrieve: `app.directive(name)
  • \\\\n
\\\\n

Parameters:

\\\\n
    \\\\n
  • `name`: Directive name.
  • \\\\n
  • `directive`: Directive definition.
  • \\\\n
\\\\nExample
app.directive('focus', {\\\\n    mounted(el) {\\\\n        el.focus();\\\\n    }\\\\n});\\\\n
callback functions.. `app.use()`\\\\n

Function: Installs a plugin.

\\\\n

Usage: `app.use(plugin, options)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `plugin`: The plugin.
  • \\\\n
  • `options` (optional): Plugin options.
  • \\\\n
\\\\n Example
import MyPlugin from './MyPlugin';\\\\napp.use(MyPlugin);\\\\n
Global configuration.. `app.mixin()`\\\\n

Function: Global mixin options.

\\\\n

Usage: `app.mixin(mixin)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `mixin`: The mixin object.
  • \\\\n
\\\\nExample
app.mixin({\\\\n    created() {\\\\n        console.log('Global mixin created');\\\\n    }\\\\n});\\\\n
Create for Server-Side Rendering (SSR)0. `app.provide()`\\\\n

Function: Provides global dependencies.

\\\\n

Usage: `app.provide(key, value)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `key`: Dependency name.
  • \\\\n
  • `value`: Dependency value.
  • \\\\n
\\\\nExample
app.provide('theme', 'dark');\\\\n
Create for Server-Side Rendering (SSR)Create for Server-Side Rendering (SSR). `app.runWithContext()`\\\\n

Function: Runs a function within the current application context.

\\\\n

Usage: `app.runWithContext(fn)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `fn`: The function to run.
  • \\\\n
\\\\nExample
app.runWithContext(() => {\\\\n    console.log('Running with app context');\\\\n});\\\\n
Create for Server-Side Rendering (SSR)Set a global error handler, triggered when uncaught. `app.version`\\\\n

Function: Get the Vue version.

\\\\n

Usage: `app.version

\\\\nExample
console.log(app.version);\\\\n
Create for Server-Side Rendering (SSR)errors occur in the application.. `app.config`\\\\n

Feature: Application configuration object.

\\\\n

Usage: `app.config

\\\\nExample
app.config.errorHandler = (err) => {\\\\n    console.error(err);\\\\n};\\\\n
Create for Server-Side Rendering (SSR)compilation behavior.. `app.config.errorHandler`\\\\n

Function: Global error handling function.

\\\\n

Usage: `app.config.errorHandler = (err, vm, info) => {}`

\\\\n

Parameters:

\\\\n
    \\\\n
  • `err`: Error object.
  • \\\\n
  • `vm`: Component instance where the error occurred.
  • \\\\n
  • `info`: Error information.
  • \\\\n
\\\\nExample
app.config.errorHandler = (err) => {\\\\n    console.error('Global error:', err);\\\\n};\\\\n
Create for Server-Side Rendering (SSR)Configure the template compiler. `app.config.warnHandler`\\\\n

Function: Global warning handler.

\\\\n

Usage: `app.config.warnHandler = (msg, vm, trace) => {}`

\\\\n

Parameters:

\\\\n
    \\\\n
  • `msg`: Warning message.
  • \\\\n
  • `vm`: Component instance where the warning occurred.
  • \\\\n
  • `trace`: Warning stack trace.
  • \\\\n
\\\\nExample
app.config.warnHandler = (msg) => {\\\\n    console.warn('Global warning:', msg);\\\\n};\\\\n
Create for Server-Side Rendering (SSR)Set a global warning handler to handle. `app.config.performance`\\\\n

Function: Enables performance tracking.

\\\\n

Usage: `app.config.performance = true

\\\\nExample
app.config.performance = true;\\\\n
Create for Server-Side Rendering (SSR)Define component option merging strategies, controlling how component. `app.config.compilerOptions`\\\\n

Function: Configure options for the template compiler.

\\\\n

Usage: `app.config.compilerOptions = { /* options */ }

\\\\nExample
app.config.compilerOptions = { whitespace: 'preserve' };\\\\n
Create for Server-Side Rendering (SSR)callback functions.. `app.config.globalProperties`\\\\n

Function: Add global properties.

\\\\n

Usage: `app.config.globalProperties = value

\\\\nExample
app.config.globalProperties.$myGlobal = 'Hello';\\\\n
Create for Server-Side Rendering (SSR)Global configuration.. `app.config.optionMergeStrategies`\\\\n

Function: Custom option merge strategies.

\\\\n

Usage: `app.config.optionMergeStrategies = strategy

\\\\nExample
app.config.optionMergeStrategies.customOption = (parent, child) => {\\\\n    return child || parent;\\\\n};\\\\n
Set a global error handler, triggered when uncaught0. `app.config.idPrefix`\\\\n

Function: Sets the component ID prefix.

\\\\n

Usage: `app.config.idPrefix = 'my-app-'`

\\\\nExample
app.config.idPrefix = 'my-app-';\\\\n
Set a global error handler, triggered when uncaughtCreate for Server-Side Rendering (SSR). `app.config.throwUnhandledErrorInProduction`\\\\n

Function: Throw unhandled errors in production environment.

\\\\n

Usage: `app.config.throwUnhandledErrorInProduction = true

\\\\nExample
app.config.throwUnhandledErrorInProduction = true;\\\\n
General API\\\\n Create for Server-Side Rendering (SSR). `version`\\\\n

Feature: Get the Vue version.

\\\\n

Usage: `Vue.version

\\\\n Example
console.log(Vue.version);\\\\n
Set a global error handler, triggered when uncaught. `nextTick()`\\\\n

Function: Execute callback after the next DOM update cycle ends.

\\\\n

Usage: `nextTick(callback)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `callback`: Callback function.
  • \\\\n
\\\\nExample
import { nextTick } from 'vue';\\\\nnextTick(() => {\\\\n    console.log('DOM updated');\\\\n});\\\\n
errors occur in the application.. `defineComponent()`\\\\n

Function: Defines a component.

\\\\n

Usage: `defineComponent(options)

\\\\n

Parameters:

\\\\n
    \\\\n
  • `options`: Component options.
  • \\\\n
\\\\nExample
import { defineComponent } from 'vue';\\\\nconst MyComponent = defineComponent({\\\\n    template: '
My Component
'\\\\n});\\\\n
← Cursor TutorialPytorch Torch Nn Ref β†’