vue3.0 + typeScript踩坑

1,477 阅读1分钟

#1.用vue+typescipt获取节点,初始化数据时出现以下报错: (Argument of type 'Vue | Element | Vue[] | Element[]' is not assignable to parameter of type 'HTMLDivElement | HTMLCanvasElement'. Type 'Vue' is not assignable to type 'HTMLDivElement | HTMLCanvasElement'. Type 'Vue' is not assignable to type 'HTMLCanvasElement'. Property 'height' is missing in type 'Vue'.)

把this.refs.box 换成 this.refs.box as HTMLCanvasElement即可。 #2.定义对象变量时提示(Property 'geoCoordMap' has no initializer and is not definitely assigned in the constructor.)

解决: public geoCoordMap: {[key: string]: number[]} = { '海门': [121.15, 31.89], '鄂尔多斯': [109.781327, 39.608266] }