F2 icon indicating copy to clipboard operation
F2 copied to clipboard

VUE3使用F2创建 Chart 对象时提示TypeError: _this.getDefaultCfg is not a function

Open cuiliang0302 opened this issue 3 years ago • 2 comments

我在vue3中使用F2创建图表时,console.log(chart)能够正常打印,说明组件引入成功,但是创建对象后,控制台提示Uncaught (in promise) TypeError: _this.getDefaultCfg is not a function请问这是怎么回事


<template>
  <div class="about">
    <canvas id="myChart" width="400" height="260"></canvas>
  </div>
</template>

<script>
import {Toast, Slider} from 'vant';
import {onMounted, inject,nextTick} from "vue";
import F2 from '@antv/f2';

export default {
  name: "Test",
  setup() {
    const chart = inject('F2');
    const data = [
      {genre: 'Sports', sold: 275},
      {genre: 'Strategy', sold: 115},
      {genre: 'Action', sold: 120},
      {genre: 'Shooter', sold: 350},
      {genre: 'Other', sold: 150}
    ]
    // Step 1: 创建 Chart 对象
    const Chart = chart.Chart({
      id: 'myChart',
      pixelRatio: window.devicePixelRatio // 指定分辨率
    });
    const drawChart = () => {
      console.log(chart)
      console.log(Chart)
    }
    onMounted(() => {
      nextTick(() => {
        drawChart()
      });
    })
    return {
      data
    }
  }
}
</script>

<style scoped>
</style>

cuiliang0302 avatar May 01 '21 13:05 cuiliang0302

同问

xiaoshan100 avatar Nov 11 '21 07:11 xiaoshan100

请问有解决吗 我的taro的项目上运行也是这样

xiaoshan100 avatar Nov 11 '21 07:11 xiaoshan100