// internal, but we need to expose these for the server-renderer and devtools _uid: number; _component: ConcreteComponent; _props: Data | null; _container: HostElement | null; _context: AppContext; _instance: ComponentInternalInstance | null;
/** * v2 compat only */ filter?(name: string): Function | undefined; filter?(name: string, filter: Function): this;
if (__DEV__) { injectNativeTagCheck(app); injectCompilerOptionsCheck(app); }
const { mount } = app; app.mount = (containerOrSelector: Element | ShadowRoot | string): any => { const container = normalizeContainer(containerOrSelector); if (!container) return;
const component = app._component; if (!isFunction(component) && !component.render && !component.template) { // __UNSAFE__ // Reason: potential execution of JS expressions in in-DOM template. // The user must make sure the in-DOM template is trusted. If it's // rendered by the server, the template should not contain any user data. component.template = container.innerHTML; // 2.x compat check if (__COMPAT__ && __DEV__) { for (let i = 0; i < container.attributes.length; i++) { const attr = container.attributes[i]; if (attr.name !== "v-cloak" && /^(v-|:|@)/.test(attr.name)) { compatUtils.warnDeprecation( DeprecationTypes.GLOBAL_MOUNT_CONTAINER, null ); break; } } } }
setconfig(v) { if (__DEV__) { warn( `app.config cannot be replaced. Modify individual options instead.` ) } },
use(plugin: Plugin, ...options: any[]) { if (installedPlugins.has(plugin)) { __DEV__ && warn(`Plugin has already been applied to target app.`) } elseif (plugin && isFunction(plugin.install)) { installedPlugins.add(plugin) plugin.install(app, ...options) } elseif (isFunction(plugin)) { installedPlugins.add(plugin) plugin(app, ...options) } elseif (__DEV__) { warn( `A plugin must either be a function or an object with an "install" ` + `function.` ) } return app },
mixin(mixin: ComponentOptions) { if (__FEATURE_OPTIONS_API__) { if (!context.mixins.includes(mixin)) { context.mixins.push(mixin) } elseif (__DEV__) { warn( 'Mixin has already been applied to target app' + (mixin.name ? `: ${mixin.name}` : '') ) } } elseif (__DEV__) { warn('Mixins are only available in builds supporting Options API') } return app },
component(name: string, component?: Component): any { if (__DEV__) { validateComponentName(name, context.config) } if (!component) { return context.components[name] } if (__DEV__ && context.components[name]) { warn(`Component "${name}" has already been registered in target app.`) } context.components[name] = component return app },
directive(name: string, directive?: Directive) { if (__DEV__) { validateDirectiveName(name) }
if (!directive) { return context.directives[name] asany } if (__DEV__ && context.directives[name]) { warn(`Directive "${name}" has already been registered in target app.`) } context.directives[name] = directive return app },
mount( rootContainer: HostElement, isHydrate?: boolean, isSVG?: boolean ): any { if (!isMounted) { // #5571 if (__DEV__ && (rootContainer asany).__vue_app__) { warn( `There is already an app instance mounted on the host container.\n` + ` If you want to mount another app on the same host container,` + ` you need to unmount the previous app by calling `app.unmount()` first.` ) } const vnode = createVNode( rootComponent asConcreteComponent, rootProps ) // store app context on the root VNode. // this will be set on the root instance on initial mount. vnode.appContext = context
returngetExposeProxy(vnode.component!) || vnode.component!.proxy } elseif (__DEV__) { warn( `App has already been mounted.\n` + `If you want to remount the same app, move your app creation logic ` + `into a factory function and create fresh app instances for each ` + `mount - e.g. `constcreateMyApp = () => createApp(App)`` ) } },
unmount() { if (isMounted) { render(null, app._container) if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { app._instance = null devtoolsUnmountApp(app) } delete app._container.__vue_app__ } elseif (__DEV__) { warn(`Cannot unmount an app that is not mounted.`) } },
provide(key, value) { if (__DEV__ && (key asstring | symbol) in context.provides) { warn( `App already provides property with key "${String(key)}". ` + `It will be overwritten with the new value.` ) }