【问题标题】:Uncaught (in promise) TypeError: Cannot read property 'length' of undefined in chartjs with VuejsUncaught (in promise) TypeError: Cannot read property 'length' of undefined in chartjs with Vuejs
【发布时间】:2021-01-05 03:55:56
【问题描述】:

我正在尝试从 Charts.vue 在我的 App.vue 中显示特定图表,以下是我试图实现的目标:

Charts.vue

<template>
  <div class="chart-container">
    <canvas :ref="`chart${chartId}`"></canvas>
  </div>
</template>

<script>
export default {
  props: {
    chartId: {
      type: String,
      required: true
    }
  } 

  ....

}
</script>

App.vue

<template>
  <div class="content-1">
    <chart :chartId="1" />  <-- Here i want to display my chart 1
  </div>

  ....

  <div class="content-8">
    <chart :chartId="8" />  <-- Here i want to display my chart 2
  </div>
</template>

<script>
import chart from './Charts'
export default{
  name: 'App',
  component: {charts}

    ....

}

没有显示任何内容,我在控制台中收到此错误:

但是假设如果我在 Charts.vue 的模板中声明为&lt;canvas ref="chart1"&gt;&lt;/canvas&gt;,然后如果我只是在我的 App.vue 模板中使用&lt;charts/&gt;,那么图表就会显示出来。

请帮我解决这个问题。

【问题讨论】:

    标签: vue.js chart.js


    【解决方案1】:

    这不只是一个错字吗? - 您正在导入“图表”,但将其用作“图表”。

    【讨论】:

    • 那是小姐,我已经更新了我的问题,即使我得到了同样的错误
    猜你喜欢
    • 1970-01-01
    • 2018-01-24
    • 2021-10-06
    • 2019-02-12
    • 2021-09-20
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多