2、变量定义为 undefined,无法被 Vue 进行数据监控
@Component
class MyComp extends Vue {
foo = undefined //无效
bar = null //有效
data() {
return {
baz : undefined // 有效
}
}
}
如果有需要在 data hooks 里定义 ts,应该怎么定义?比如需要定义 baz 的类型
handleCollapse(e: HTMLElement ) {
// const targetEl = e.target as HTMLInputElement
const targetEl = e.target
const contentEl = targetEl.parentElement.nextSibling
@click 事件中的 e 应该怎么定义?试了都不行,
(property) Node.parentElement: HTMLElement | null
Object is possibly 'null'.Vetur(2531)