ts contentWindow err: ‘HTMLElement | null’ is not assignable to type ‘HTMLElement’. Type ‘null’ i...

11111.jpg

解决:

// 1. 将contentWindow保存到变量
const iWindow = (this.$refs.editorFrame as HTMLIFrameElement).contentWindow; // 此时的iWindow类型为 Window | null
// 2. 将iWindow进行断言
iWindow as Window

// 完整代码
getIframeWindow(): Window {
    const iFrame = (this.$refs.editorFrame as HTMLIFrameElement).contentWindow;
    return iFrame as Window
  }

你可能感兴趣的:(ts contentWindow err: ‘HTMLElement | null’ is not assignable to type ‘HTMLElement’. Type ‘null’ i...)