fix(hooks): vm may be null (#12058)

This commit is contained in:
Liu Bo 2023-03-16 21:31:16 +08:00 committed by GitHub
parent b5bf0ebf30
commit 8b3250217e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,6 @@ import { computed, getCurrentInstance } from 'vue'
import type { ComputedRef } from 'vue'
export const useProp = <T>(name: string): ComputedRef<T | undefined> => {
const vm = getCurrentInstance()!
return computed(() => (vm.proxy?.$props as any)[name] ?? undefined)
const vm = getCurrentInstance()
return computed(() => (vm?.proxy?.$props as any)?.[name])
}