【发布时间】:2021-02-13 04:51:00
【问题描述】:
我有一个ref:
const editItem = ref<object | null>(null)
这是它的一个示例值:
{
id: 1,
title: 'Harry Potter',
author: 'J.K. Rowling',
created: '30-08-2000',
}
如果我运行console.log(editItem.value),我会看到这个对象:
但是当我尝试用console.log(editItem.value.author) 读取值的author 时,我看到了这个错误:
Object is possibly 'null'.
【问题讨论】:
-
你能提供一个codesandbox的例子吗?你可以丰富这个codesandbox.io/s/vue-3-ts-y7bdv
标签: typescript ref vuejs3 vue-composition-api