From 77ba15b21ee6af6321fc51d72db72c61ca1ccba0 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 24 Jun 2020 18:25:47 +0800 Subject: [PATCH] feat: auto install when using CDN (#403) --- src/index.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4d149bf1..325bd340 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,5 @@ import Vue, { VueConstructor } from 'vue' import { Data, SetupFunction, SetupContext } from './component' -import { currentVue } from './runtimeContext' import { install } from './install' import { mixin } from './setup' @@ -10,17 +9,12 @@ declare module 'vue/types/options' { } } -const _install = (Vue: VueConstructor) => install(Vue, mixin) -const plugin = { - install: _install, -} -// Auto install if it is not done yet and `window` has `Vue`. -// To allow users to avoid auto-installation in some cases, -if (currentVue && typeof window !== 'undefined' && window.Vue) { - _install(window.Vue) +const VueCompositionAPI = { + install: (Vue: VueConstructor) => install(Vue, mixin), } -export default plugin +export default VueCompositionAPI + export { nextTick } from './nextTick' export { default as createElement } from './createElement' export { SetupContext } @@ -40,3 +34,8 @@ export * from './apis/lifecycle' export * from './apis/watch' export * from './apis/computed' export * from './apis/inject' + +// auto install when using CDN +if (typeof window !== 'undefined' && window.Vue) { + window.Vue.use(VueCompositionAPI) +}