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'
22import { AnyObject } from './types/basic'
33import { hasSymbol , hasOwn , isPlainObject , assert } from './utils'
44import { isRef } from './reactivity'
5- import { setVueConstructor , isVueRegistered } from './runtimeContext'
5+ import {
6+ setVueConstructor ,
7+ isVueRegistered ,
8+ isPluginInstalled ,
9+ } from './runtimeContext'
610import { mixin } from './mixin'
711
812/**
@@ -40,7 +44,7 @@ function mergeData(from: AnyObject, to: AnyObject): Object {
4044}
4145
4246export function install ( Vue : VueConstructor ) {
43- if ( isVueRegistered ( ) ) {
47+ if ( isPluginInstalled ( ) || isVueRegistered ( Vue ) ) {
4448 if ( __DEV__ ) {
4549 assert (
4650 false ,
@@ -52,10 +56,7 @@ export function install(Vue: VueConstructor) {
5256
5357 if ( __DEV__ ) {
5458 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.` )
5960 }
6061 }
6162
Original file line number Diff line number Diff line change 1- import { VueConstructor } from 'vue'
1+ import type { VueConstructor } from 'vue'
22import { ComponentInstance } from './component'
3- import { assert } from './utils'
3+ import { assert , hasOwn } from './utils'
44
55let vueConstructor : VueConstructor | null = null
66let currentInstance : ComponentInstance | null = null
77
8- export function isVueRegistered ( ) {
8+ const PluginInstalledFlag = '__composition_api_installed__'
9+
10+ export function isPluginInstalled ( ) {
911 return ! ! vueConstructor
1012}
1113
14+ export function isVueRegistered ( Vue : VueConstructor ) {
15+ return hasOwn ( Vue , PluginInstalledFlag )
16+ }
17+
1218export function getVueConstructor ( ) : VueConstructor {
1319 if ( __DEV__ ) {
1420 assert (
@@ -22,6 +28,11 @@ export function getVueConstructor(): VueConstructor {
2228
2329export function setVueConstructor ( Vue : VueConstructor ) {
2430 vueConstructor = Vue
31+ Object . defineProperty ( Vue , PluginInstalledFlag , {
32+ configurable : true ,
33+ writable : true ,
34+ value : true ,
35+ } )
2536}
2637
2738export function getCurrentInstance ( ) : ComponentInstance | null {
You can’t perform that action at this time.
0 commit comments