Skip to content

Commit c2010b1

Browse files
committed
fix: resolve vnode
1 parent f8d1ade commit c2010b1

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/composables/use-props.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function useProps<T>(currentInstance = getCurrentInstance()): T {
1919

2020
const updateProps = computed(() => {
2121
const attrs = {} as Record<string, any>
22-
const $attrs = currentInstance!.proxy?.$attrs
22+
const $attrs = isVue2 ? currentInstance?.$attrs : currentInstance?.proxy.$attrs
2323
if ($attrs) {
2424
for (const attr in $attrs) {
2525
// make a backup copy of attrs in props format
@@ -29,12 +29,12 @@ export function useProps<T>(currentInstance = getCurrentInstance()): T {
2929

3030
return {
3131
...attrs,
32-
...(isVue2 ? (currentInstance!.proxy as any)?._props : currentInstance?.props)
32+
...(isVue2 ? currentInstance?._props : currentInstance?.props)
3333
}
3434
})
3535

3636
if (isVue2) {
37-
const set = (currentInstance?.proxy as any).$set
37+
const set = (currentInstance as any).$set
3838
watchEffect(
3939
() => {
4040
const updatePropsValue = updateProps.value

src/vnode/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { VNode } from 'vue-module-demi'
22
import { isVue2 } from '../version'
33
import type { ComponentInternalInstance } from '../types'
4+
import { getCurrentInstance } from '../composables/utils'
45

56
export * from './children'
67
export * from './props'
78
export * from './types'
89

910
export function resolveVNode<T extends VNode = VNode>(
10-
instance: ComponentInternalInstance | null
11+
instance: ComponentInternalInstance | null = getCurrentInstance()
1112
): T | null | undefined {
12-
return isVue2 ? (instance?.proxy as any)?.$vnode : instance?.vnode
13+
return isVue2 ? (instance as any)?.$vnode : instance?.vnode
1314
}

0 commit comments

Comments
 (0)