MCPcopy
hub / github.com/vuejs/composition-api / createApp

Function createApp

src/apis/createApp.ts:21–76  ·  view source on GitHub ↗
(rootComponent: any, rootProps: any = undefined)

Source from the content-addressed store, hash-verified

19}
20
21export function createApp(rootComponent: any, rootProps: any = undefined): App {
22 const V = getVueConstructor()!
23
24 let mountedVM: Vue | undefined = undefined
25
26 let provide: Record<any, any> = {}
27
28 const app: App = {
29 config: V.config,
30 use: V.use.bind(V),
31 mixin: V.mixin.bind(V),
32 component: V.component.bind(V),
33 provide<T>(key: InjectionKey<T> | symbol | string, value: T) {
34 provide[key as any] = value
35 return this
36 },
37 directive(name: string, dir?: Directive | undefined): any {
38 if (dir) {
39 V.directive(name, dir as any)
40 return app
41 } else {
42 return V.directive(name)
43 }
44 },
45 mount: (el, hydrating) => {
46 if (!mountedVM) {
47 mountedVM = new V({
48 propsData: rootProps,
49 ...rootComponent,
50 provide: { ...provide, ...rootComponent.provide },
51 })
52 mountedVM.$mount(el, hydrating)
53 return mountedVM
54 } else {
55 if (__DEV__) {
56 warn(
57 `App has already been mounted.\n` +
58 `If you want to remount the same app, move your app creation logic ` +
59 `into a factory function and create fresh app instances for each ` +
60 `mount - e.g. \`const createMyApp = () => createApp(App)\``
61 )
62 }
63 return mountedVM
64 }
65 },
66 unmount: () => {
67 if (mountedVM) {
68 mountedVM.$destroy()
69 mountedVM = undefined
70 } else if (__DEV__) {
71 warn(`Cannot unmount an app that is not mounted.`)
72 }
73 },
74 }
75 return app
76}

Callers 10

createApp.spec.tsFile · 0.90
mountWithModuleFunction · 0.90
h.spec.tsFile · 0.90
apiInject.spec.tsFile · 0.90

Calls 2

getVueConstructorFunction · 0.90
warnFunction · 0.90

Tested by 1

mountWithModuleFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…