【发布时间】:2018-08-21 21:34:26
【问题描述】:
我正在联系 API,将结果保存在数据中,然后使用 v-for 在表格中列出该数据。其中一列包含一个 vuechart,但我似乎无法让它显示任何内容。如果我检查创建的组件,它在 props 数组中有数据,但没有骰子。
将vuechart图表放入v-for循环有什么特别之处吗?还是我没有正确传递一些东西?
代码如下:
趋势图.js
import {Bar} from 'vue-chartjs'
export default {
extends: Bar,
name: 'TrendChart',
props: ['data', 'options'],
mounted() {
this.renderChart(this.data, this.options)
}
}
结果.vue
<table>
<tr v-for="result in results">
...
<td>
<trend-chart :data="result.trends", :options="{responsive: false, maintainAspectRatio: false}"></trend-chart>
...
</table>
如果我在渲染后检查组件,我会看到道具在那里,但数据似乎没有进入图表,或者我假设,我从未见过成功的(这是Vue开发工具的文本格式输出):
props
chartId:"bar-chart"
cssClasses:""
data:Array[12]
height:400
options:Object
maintainAspectRatio:false
responsive:false
plugins:Array[0]
styles:undefined
width:400
data
_chart:Unknown Component
_plugins:Array[0]
【问题讨论】:
标签: vue.js vue-chartjs