Argument of type 'XX' is not assignable to parameter of type 'XX'

简介: Argument of type 'XX' is not assignable to parameter of type 'XX'

Vue2.6 , Typescript3 项目引入 Echarts 时报错,内容如下

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 missing the following properties from type 'HTMLCanvasElement': height, width, getContext, toBlob, and 243 more.Vetur(2345)

ECharts.vue

<template>
  <div>
    <div ref="main" style="width:500px;height:500px;"></div>
  </div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import * as echarts from 'echarts'
@Component({
  components: {}
})
export default class ECharts extends Vue {
  private mounted() {
    console.info('mounted')
    console.info(echarts)
    console.info(this.$refs.main)
    const mainEle = this.$refs.main
    const myChart = echarts.init(mainEle)
    myChart.setOption({
      title: {
        text: 'ECharts 入门示例'
      },
      tooltip: {},
      xAxis: {
        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
      },
      yAxis: {},
      series: [
        {
          name: '销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        }
      ]
    })
    console.info(myChart)
  }
}
</script>
<style scoped lang="scss"></style>

错误出现在 ECharts.vue 第17行 const mainEle = this.$refs.main

解决方案

this.$refs.main 内容修改为 this.$refs.main as HTMLDivElement 即可

相关文章
|
2月前
|
JavaScript API
required string parameter ‘XXX‘is not present 的几种情况
required string parameter ‘XXX‘is not present 的几种情况
29 0
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
|
10月前
|
SQL
Parameter ‘id‘ not found. Available parameters are [collection, list]
Parameter ‘id‘ not found. Available parameters are [collection, list]
126 0
|
7月前
|
人工智能 自然语言处理 语音技术
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
52 0
GenImageInterleaved Wrong type of control parameter 1
GenImageInterleaved Wrong type of control parameter 1
|
7月前
|
C++
Reference Parameter
Reference Parameter(引用参数)是一种 C++ 编程语言中的参数传递方式。它允许将一个变量的引用(而不是副本)作为函数参数传递。引用参数的主要优点是可以避免在函数内部对实参进行拷贝操作,从而提高代码的效率。
36 1
|
9月前
|
JSON 数据格式
Required request parameter ‘name‘ for method parameter type String is not present 报错解决方法
Required request parameter ‘name‘ for method parameter type String is not present 报错解决方法
3341 0
|
9月前
|
Scala
TYPE
TYPE
90 0
|
10月前
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]
Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……
Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……
174 0