【发布时间】: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 的模板中声明为<canvas ref="chart1"></canvas>,然后如果我只是在我的 App.vue 模板中使用<charts/>,那么图表就会显示出来。
请帮我解决这个问题。
【问题讨论】: