1
1
import type Vue from 'vue'
2
2
import { VueConstructor } from 'vue'
3
+ import { Directive } from '../component/directives'
3
4
import { getVueConstructor } from '../runtimeContext'
4
5
import { warn } from '../utils'
5
6
@@ -9,7 +10,8 @@ export interface App<T = any> {
9
10
use : VueConstructor [ 'use' ]
10
11
mixin : VueConstructor [ 'mixin' ]
11
12
component : VueConstructor [ 'component' ]
12
- directive : VueConstructor [ 'directive' ]
13
+ directive ( name : string ) : Directive | undefined
14
+ directive ( name : string , directive : Directive ) : this
13
15
mount : Vue [ '$mount' ]
14
16
unmount : Vue [ '$destroy' ]
15
17
}
@@ -19,12 +21,19 @@ export function createApp(rootComponent: any, rootProps: any = undefined): App {
19
21
20
22
let mountedVM : Vue | undefined = undefined
21
23
22
- return {
24
+ const app : App = {
23
25
config : V . config ,
24
26
use : V . use . bind ( V ) ,
25
27
mixin : V . mixin . bind ( V ) ,
26
28
component : V . component . bind ( V ) ,
27
- directive : V . directive . bind ( V ) ,
29
+ directive ( name : string , dir ?: Directive | undefined ) : any {
30
+ if ( dir ) {
31
+ V . directive ( name , dir as any )
32
+ return app
33
+ } else {
34
+ return V . directive ( name )
35
+ }
36
+ } ,
28
37
mount : ( el , hydrating ) => {
29
38
if ( ! mountedVM ) {
30
39
mountedVM = new V ( { propsData : rootProps , ...rootComponent } )
@@ -51,4 +60,5 @@ export function createApp(rootComponent: any, rootProps: any = undefined): App {
51
60
}
52
61
} ,
53
62
}
63
+ return app
54
64
}
0 commit comments