问题
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