在vue3.0+typescript+echarts5.0项目中,初始化图表,

public myChart = echarts.init(document.getElementById("main"))

控制台出现以下报错

Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'.
  Type 'null' is not assignable to type 'HTMLElement'.

解决方法:增加类型断言(Type Assertion)

public main: HTMLElement = document.getElementById("main") as HTMLElement;
public myChart = echarts.init(this.main);
Logo

前往低代码交流专区

更多推荐