Vetur 在下面这一行加下划线:
const firstRef = ref<HTMLElement>(null)
没有重载匹配此调用。 Overload 1 of 3, '(raw: HTMLElement): Ref',给出了以下错误。 “null”类型的参数不能分配给“HTMLElement”类型的参数。 Overload 2 of 3, '(raw: HTMLElement): Ref',给出了以下错误。 “null”类型的参数不能分配给“HTMLElement”类型的参数。Vetur(2769)
这是一个浓缩的上下文。任何想法我做错了什么?
<template>
<input id="first" ref="firstRef">
<button type="button" @click.prevent="focusFirst">Focus</button>
</template>
<script lang="ts">
import { defineComponent, ref } from "@vue/composition-api"
export default defineComponent({
name: "Test",
setup() {
const firstRef = ref<HTMLElement>(null)
const focusFirst = () => {
const theField = firstRef.value
theField.focus()
}
return { focusFirst }
}
</script>