Skip to content

Commit b01f1e4

Browse files
committed
fix: use registered Vue instance for warning
1 parent a33e400 commit b01f1e4

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/runtimeContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
UnionToIntersection,
1010
isFunction,
1111
} from './utils'
12-
import Vue$1 from 'vue'
12+
import type Vue$1 from 'vue'
1313

1414
let vueDependency: VueConstructor | undefined = undefined
1515

src/utils/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Vue from 'vue'
1+
import { getRegisteredVueOrDefault } from '../runtimeContext'
22

33
const toString = (x: any) => Object.prototype.toString.call(x)
44

@@ -99,7 +99,9 @@ export function isUndef(v: any): boolean {
9999
}
100100

101101
export function warn(msg: string, vm?: Vue) {
102-
Vue.util.warn(msg, vm)
102+
const Vue = getRegisteredVueOrDefault()
103+
if (!Vue || !Vue.util) console.warn(`[vue-composition-api] ${msg}`)
104+
else Vue.util.warn(msg, vm)
103105
}
104106

105107
export function logError(err: Error, vm: Vue, info: string) {

test/v3/runtime-core/apiWatch.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import {
88
shallowReactive,
99
nextTick,
1010
} from '../../../src'
11-
import Vue from 'vue'
11+
import { getRegisteredVueOrDefault } from '../../../src/runtimeContext'
1212

1313
// reference: https://vue-composition-api-rfc.netlify.com/api.html#watch
1414

1515
describe('api: watch', () => {
16+
const Vue = getRegisteredVueOrDefault()
1617
// const warnSpy = jest.spyOn(console, 'warn');
1718
const warnSpy = jest.spyOn((Vue as any).util, 'warn')
1819

0 commit comments

Comments
 (0)