Every Vue application exposes a config object that contains the configuration settings for that application:
const app = Vue.createApp({})
app.config ={...}
App Configuration
Description
H5
App Terminal
WeChat Mini Program
Description
errorHandler
Specifies a handler function to handle uncaught errors thrown during the execution of the component's render method and by the listener. Details
√
√
√
warnHandler
Specify a custom handler for Vue's runtime warnings. Details
√
√
√
globalProperties
Adds a global property that can be accessed in any component instance within the application. Details
√
√
√
isCustomElement
Specifies a method to identify custom elements defined outside of Vue. Details
√
√
√
optionMergeStrategies
Define merge strategies for custom options. Details
√
√
√
performance
Set to true to enable performance tracking of component initialization, compilation, rendering and updates in the performance/timeline panel of the browser dev tools. Details
In Vue 3, APIs that globally mutate Vue's behavior are now moved to application instances created by the new createApp method. In addition, their effects are now scoped to that specific application's instance:
Calling createApp returns an application instance. This instance provides an application context. The entire component tree mounted by the application instance share the same context, which provides the configurations that were previously "global" in Vue 2.x.
In addition, since the createApp method returns the application instance itself, you can chain other methods after it which can be found in the following sections.
Returns an application instance that provides the application context. The entire component tree mounted by an application instance shares the same context. Details
√
√
√
h
Returns a "virtual node", often abbreviated VNode: a plain object that contains information describing to Vue what kind of node it should render on the page, including descriptions of all child nodes. Details
√
x
x
defineComponent
By implementation, defineComponent only returns the object passed to it. However, in terms of type, the returned value has a synthetic type constructor for manual rendering functions, TSX and IDE tool support. Details
√
x
x
defineAsyncComponent
Creates an asynchronous component that is loaded only when needed. Details
√
x
x
resolveComponent
Allows component to be resolved by name if available in the current application instance. Returns a Component. Details
√
x
x
resolveDynamicComponent
allows to resolve a component using the same mechanism as component :is="". Details
√
x
x
resolveDirective
Allows a directive to be resolved by its name if available in the current application instance. Returns a Directive. Details
√
x
x
withDirectives
allows directives to be applied to a VNode. Returns a VNode containing application instructions. Details
√
x
x
createRenderer
createRenderer function accepts two generic parameters: HostNode and HostElement, corresponding to the Node and Element types in the host environment. Details
√
x
x
nextTick
Defer callback execution until after the next DOM update cycle. Use it immediately after changing some data to wait for DOM to update. Details
A function that returns the data object of the component instance. Details
√
√
√
props
props can be an array or an object to receive data from the parent component. Details
√
√
√
computed
The computed property will be mixed into the component instance. The this context of all getters and setters is automatically bound to the component instance. Details
√
√
√
methods
methods will be mixed into the component instance. These methods can be accessed directly through the VM instance, or used in instruction expressions. this in a method is automatically bound to the component instance. Details
√
√
√
watch
An object, the key is the expression to watch, and the value is the corresponding callback function. The value can also be a method name, or an object containing options. Details
√
√
√
emits
emits can be an array or object to fire custom events from the component, emits can be a simple array, or an object instead, allowing configuration and event validation. Details
Called after instance initialization, before data observer and event/watcher event configuration. Details
√
√
√
created
Called immediately after the instance is created. Details
√
√
√
beforeMount
Called before the mount starts: the associated render function is called for the first time. Details
√
√
√
mounted
Called after the instance is mounted, when Vue.createApp({}).mount() is replaced by the newly created vm.$el. Details
√
√
√
beforeUpdate
Called when data is updated, before the virtual DOM is patched. Details
√
√
√
updated
This hook is called after the virtual DOM is re-rendered and patched due to data changes. Details
√
√
√
activated
Called when a component cached by keep-alive is activated. Details
√
√
x
deactivated
Called when a component cached by keep-alive is deactivated. Details
√
√
x
beforeUnmount
Called before the component instance is unmounted. At this stage, the instance is still completely normal. Details
√
√
√
unmounted
Called after the component instance is unmounted. When this hook is called, all directives of the component instance are unbound, all event listeners are removed, and all child component instances are unloaded. Details
√
√
√
errorCaptured
Called when an error from a descendant component is captured. This hook receives three parameters: the error object, the component instance where the error occurred, and a string containing information about the source of the error. Details
√
√
√
renderTracked
Called when the tracked virtual DOM is re-rendered. The hook receives debugger event as a parameter. This event tells you which action tracked the component and the target object and key for that action. Details
√
√
√
renderTriggered
When the virtual DOM is re-rendered to triggered.Similarly to renderTracked, receive a debugger event as a parameter. This event tells you what action triggered the re-render, and the target object and key for that action. Details
Receives an array of mixin objects. These mixins can contain instance options just like normal instance objects, and these options will be merged into the final option, using specific option merge logic. Details
√
√
√
extends
allows a declaration to extend another component (can be a simple options object or a constructor). This is mainly to facilitate extending single-file components. Details
√
√
√
provide / inject
The pair of options needs to be used together to allow an ancestor component to inject a dependency into all its descendants, no matter how deep the component hierarchy is, and it will always take effect as long as the upstream and downstream relationships are established. Details
√
√
√
setup
The setup function is a new component option. It acts as an entry point for using the composition API inside the component. Details
allows the component template to call itself recursively. Note that when a component is registered globally with Vue.createApp({}).component({}), the global ID is automatically used as the component's name. Details
√
√
√
delimiters
Sets the delimiters used for text insertion within templates. Details
√
x
x
inheritAttrs
By default parent-scoped attribute bindings (attribute bindings) that are not considered props will "fall back" and be applied to the root element of child components as normal HTML attributes superior. By setting inheritAttrs to false when writing components that wrap a target element or another component, these default behaviors will be removed. Details
The data object observed by the component instance. A component instance proxies access to its data object property. Details
√
√
√
$props
The props object received by the current component. A component instance proxies access to its props object property. Details
√
√
√
$el
The root DOM element used by the component instance. Details
√
x
x
$options
Init options for the current component instance. Useful when you need to include custom property in options. Details
√
√
√
$parent
Parent instance, if the current instance has one. Details
√
√
√
The built-in tags such as view and text on the H5 side are Vue Component implementation, $parent will get these to built-in components, the problem is that this.$parent is inconsistent with other platforms, the solution is to use this.$parent.$parent to get or customize the root node of the component Changed from view to div
Listen to changes in reactive property or function evaluation results on component instances. Details
√
√
√
$emit
Trigger an event on the current instance. Additional parameters are passed to the listener callback. Details
√
√
√
$forceUpdate
Forces the component instance to re-render. Note that it only affects the instance itself and subcomponents that insert the contents of the slot, not all subcomponents. Details
√
√
√
$nextTick
Delay callback execution until after the next DOM update loop. Use it immediately after modifying the data, then wait for the DOM to update. Details
Transition effect as a single element/component. Details
√
x
x
transition-group
As a transition effect for multiple elements/components. Details
√
x
x
keep-alive
When wrapping dynamic components, inactive component instances are cached instead of destroying them, mainly to preserve component state or avoid re-rendering. Details
√
x
x
slot
Distribute slots as content in component templates. The slot element itself will be replaced. Details
√
√
√
teleport
Move part of the template to a different location in the DOM than the Vue app. Details
Takes an object (reactive or plain) or ref and returns a read-only proxy for the original proxy. Details
√
√
√
isProxy
Checks whether the object is a reactive or readonly created proxy. Details
√
√
√
isReactive
Checks if the object is a reactive proxy created by reactive. Details
√
√
√
isReadonly
Checks if the object is a read-only proxy created by readonly. Details
√
√
√
toRaw
Returns the raw object of the reactive or readonly proxy. Details
√
√
√
markRaw
Marks an object so that it will never be converted to a proxy. Return the object itself. Details
√
√
√
shallowReactive
Creates a reactive proxy that tracks the reactivity of its own property, but does not perform deep reactive transformations of nested objects (exposing primitive values). Details
√
√
√
shallowReadonly
Creates a proxy that makes its own property read-only, but does not perform deep read-only conversions of nested objects (exposing primitive values). Details
Takes an internal value and returns a reactive and mutable ref object. ref objects have a single property .value that points to the internal value. Details
√
√
√
unref
Returns the internal value if the argument is ref, otherwise returns the argument itself. This is val = isRef(val) ? val.value : val. Details
√
√
√
toRef
can be used to create a ref for a property property on the source reactive object. The ref can then be passed out, maintaining a reactive connection to its source property. Details
√
√
√
toRefs
Converts a reactive object to a normal object, where each property of the resulting object is a ref pointing to the corresponding property of the original object. Details
Use the getter function and return an immutable reactive ref object for the value returned from the getter. Details
√
√
√
watchEffect
Runs a function as soon as its dependencies are tracked reactively, and re-runs it when dependencies are changed. Details
√
√
√
watch
The watch API is exactly equivalent to the option API this.$watch (and the corresponding watch option). watch needs to listen to a specific data source and has side effects in a separate callback function. Details
A component option that is executed before the component is created, once the props are resolved, and serves as the entry point to the composite API. Details
√
√
√
Lifecycle Hooks
Lifecycle hooks can be registered using the directly imported onX function. [Details](https://v3.cn.vuejs.org/api/composition-api.html#%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E9 %92%A9%E5%AD%90)
√
√
√
Provide / Inject
provide and inject enable dependency injection. Both can only be called during setup() using the currently active instance. Details
√
√
√
getCurrentInstance
Allows access to internal component instances useful for advanced use or library creators. Details
uni-app has built-in Vuex, for use in app, please refer to hello-uniappstore/index.js .
//store.jsimport{createStore}from'vuex'const store =createStore({state:{...},mutations:{...},actions:{...}})exportdefault store
//main.jsimport App from'./App'import{createSSRApp}from'vue'import store from'./store'exportfunctioncreateApp(){const app =createSSRApp(App)
app.use(store)return{
app
}}//test.vue When using:import{mapState,mapMutations}from'vuex'
Since onError is not a complete life cycle, only a method of catching errors is provided, and a callback function named onError can be added to the root component of the app. as follows:
exportdefault{// Only apps have an onLaunch lifecycleonLaunch(){// ...},// capture app erroronError(err){
console.log(err)}}
# 4. Component property settings do not take effect
When some properties are repeatedly set to the same value, they are not synchronized to the View layer. For example, every time you set the scroll-top property of a scroll-view component to 0, it only gets back to the top the first time. This is due to the props unidirectional data flow feature. When the actual value of scroll top inside the component changes, the binding properties do not change with it.
There are two solutions (take the scroll-view component as an example):
Monitor the scroll event, record the value of the internal change of the component, and set the current value of the record before setting the new value
exportdefault{data(){return{scrollTop:0,}},methods:{scroll:function(e){// If you use this method, please add debounce by yourselfthis.scrollTop = e.detail.scrollTop
},goTop:function(e){this.scrollTop =0}}}
The second solution may cause jitter in some components, and the first solution is recommended .