Uncaught (in promise) TypeError: Cannot read property 'length' of undefined in chartjs with Vuejs

▼魔方 西西 提交于 2021-01-07 01:37:51

问题


I am trying to display particular chart in my App.vue from Charts.vue, Below is what I tried to achieve:

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}

    ....

}

Nothing is displayed, and i get this error in my console:

But suppose if i declare as <canvas ref="chart1"></canvas> in template of Charts.vue and then if i just use <charts/> in my template of App.vue, then the chart is displayed.

Please do help me in order to solve this issue.


回答1:


Isn't this just a typo? - you are importing "chart", but using it as "charts".



来源:https://stackoverflow.com/questions/65573051/uncaught-in-promise-typeerror-cannot-read-property-length-of-undefined-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!