网页
综合
更新时间 2026-11-13 15:32:29
Application API | Vue.js
自动蜘蛛
vuejs.org
正文约 3654 字
Reactivity: Utilities
Reactivity: Advanced
Dependency Injection
Options: Composition
Syntax Specification
Server-Side Rendering
TypeScript Utility Types
Creates an application instance.
The first argument is the root component. The second optional argument is the props to be passed to the root component.
With inline root component:
With imported component:
See also Guide - Creating a Vue Application
Creates an application instance in SSR Hydration mode. Usage is exactly the same as createApp().
Mounts the application instance in a container element.
The argument can either be an actual DOM element or a CSS selector (the first matched element will be used). Returns the root component instance.
If the component has a template or a render function defined, it will replace any existing DOM nodes inside the container. Otherwise, if the runtime compiler is available, the innerHTML of the container will be used as the template.
In SSR hydration mode, it will hydrate the existing DOM nodes inside the container. If there are mismatches, the existing DOM nodes will be morphed to match the expected output.
For each app instance, mount() can only be called once.
Can also mount to an actual DOM element:
Unmounts a mounted application instance, triggering the unmount lifecycle hooks for all components in the application's component tree.
Registers a callback to be called when the app is unmounted.
Registers a global component if passing both a name string and a component definition, or retrieves an already registered one if only the name is passed.
See also Component Registration
Registers a global custom directive if passing both a name string and a directive definition, or retrieves an already registered one if only the name is passed.
See also Custom Directives
Expects the plugin as the first argument, and optional plugin options as the second argument.
The plugin can either be an object with an install() method, or just a function that will be used as the install() method. The options (second argument of app.use()) will be passed along to the plugin's install() method.
When app.use() is called on the same plugin multiple times, the plugin will be installed only once.
Applies a global mixin (scoped to the application). A global mixin applies its included options to every component instance in the application.
Mixins are supported in Vue 3 mainly for backwards compatibility, due to their widespread use in ecosystem libraries. Use of mixins, especially global mixins, should be avoided in application code.
For logic reuse, prefer Composables instead.
Provide a value that can be injected in all descendant components within the application.
Expects the injection key as the first argument, and the provided value as the second. Returns the application instance itself.
Inside a component in the application:
Execute a callback with the current app as injection context.
Expects a callback function and runs the callback immediately. During the synchronous call of the callback, inject() calls are able to look up injections from the values provided by the current app, even when there is no current active component instance. The return value of the callback will also be returned.
Provides the version of Vue that the application was created with. This is useful inside plugins, where you might need conditional logic based on different Vue versions.
Performing a version check inside a plugin:
See also Global API - version
Every application instance exposes a config object that contains the configuration settings for that application. You can modify its properties (documented below) before mounting your application.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。