File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,11 @@ import type { VueConstructor } from 'vue'
2
2
import { AnyObject } from './types/basic'
3
3
import { hasSymbol , hasOwn , isPlainObject , assert } from './utils'
4
4
import { isRef } from './reactivity'
5
- import { setVueConstructor , isVueRegistered } from './runtimeContext'
5
+ import {
6
+ setVueConstructor ,
7
+ isVueRegistered ,
8
+ isPluginInstalled ,
9
+ } from './runtimeContext'
6
10
import { mixin } from './mixin'
7
11
8
12
/**
@@ -40,7 +44,7 @@ function mergeData(from: AnyObject, to: AnyObject): Object {
40
44
}
41
45
42
46
export function install ( Vue : VueConstructor ) {
43
- if ( isVueRegistered ( ) ) {
47
+ if ( isPluginInstalled ( ) || isVueRegistered ( Vue ) ) {
44
48
if ( __DEV__ ) {
45
49
assert (
46
50
false ,
@@ -52,10 +56,7 @@ export function install(Vue: VueConstructor) {
52
56
53
57
if ( __DEV__ ) {
54
58
if ( ! Vue . version . startsWith ( '2.' ) ) {
55
- assert (
56
- false ,
57
- `@vue/composition-api only works with Vue 2, v${ Vue . version } found.`
58
- )
59
+ assert ( false , `only works with Vue 2, v${ Vue . version } found.` )
59
60
}
60
61
}
61
62
Original file line number Diff line number Diff line change 1
- import { VueConstructor } from 'vue'
1
+ import type { VueConstructor } from 'vue'
2
2
import { ComponentInstance } from './component'
3
- import { assert } from './utils'
3
+ import { assert , hasOwn } from './utils'
4
4
5
5
let vueConstructor : VueConstructor | null = null
6
6
let currentInstance : ComponentInstance | null = null
7
7
8
- export function isVueRegistered ( ) {
8
+ const PluginInstalledFlag = '__composition_api_installed__'
9
+
10
+ export function isPluginInstalled ( ) {
9
11
return ! ! vueConstructor
10
12
}
11
13
14
+ export function isVueRegistered ( Vue : VueConstructor ) {
15
+ return hasOwn ( Vue , PluginInstalledFlag )
16
+ }
17
+
12
18
export function getVueConstructor ( ) : VueConstructor {
13
19
if ( __DEV__ ) {
14
20
assert (
@@ -22,6 +28,11 @@ export function getVueConstructor(): VueConstructor {
22
28
23
29
export function setVueConstructor ( Vue : VueConstructor ) {
24
30
vueConstructor = Vue
31
+ Object . defineProperty ( Vue , PluginInstalledFlag , {
32
+ configurable : true ,
33
+ writable : true ,
34
+ value : true ,
35
+ } )
25
36
}
26
37
27
38
export function getCurrentInstance ( ) : ComponentInstance | null {
You can’t perform that action at this time.
0 commit comments