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

简介: Vue2.6 , Typescript3 项目引入 Echarts 时报错,错误出现在 ECharts.vue 第17行 const mainEle = this.$refs.main,将 this.$refs.main 内容修改为 this.$refs.main as HTMLDivElement 即可。

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 即可


目录
相关文章
|
7月前
|
JavaScript API
required string parameter ‘XXX‘is not present 的几种情况
required string parameter ‘XXX‘is not present 的几种情况
2023 0
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
解决Missing cookie ‘JssionId‘ for method parameter of type String问题
解决Missing cookie ‘JssionId‘ for method parameter of type String问题
175 0
|
SQL
Parameter ‘id‘ not found. Available parameters are [collection, list]
Parameter ‘id‘ not found. Available parameters are [collection, list]
242 0
|
7月前
Argument of type 'XX' is not assignable to parameter of type 'XX'
Argument of type 'XX' is not assignable to parameter of type 'XX'
142 0
|
人工智能 自然语言处理 语音技术
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“问题解决
131 0
|
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 报错解决方法
3752 0
|
Scala
TYPE
TYPE
146 0
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]