【发布时间】:2018-08-02 19:54:43
【问题描述】:
我正在使用 Vue-Chartjs 库,我正在尝试制作折线图。好吧,我已经用下面的代码完成了它,它有效!图表已绘制。但是当我更改我的Vue Data 中的任何变量的值时(例如这个test 输入,在示例中。)。它在控制台中评估此错误。我认为这是因为 VueChartJS,因为如果我删除图表,一切正常。
TypeError:将循环结构转换为 JSON
line.js
import {Line, mixins} from 'vue-chartjs'
const { reactiveProp } = mixins
export default {
extends: Line,
mixins: [reactiveProp],
props: ['options'],
mounted() {
this.renderChart(this.chartData, this.options);
}
}
dashboard.vue
<line-chart :chart-data="dataCollection" :height="100"></line-chart>
<input v-model="test">
import LineChart from './line-chart.js';
export default {
components: {LineChart},
data: () => ({
dataCollection: {},
test: "some input"
}),
created () {
this.dataCollection = {
"labels": ["0:00", "1:00", "2:00", "3:00", "4:00", "5:00"],
"datasets": [{
"label": "Test",
"backgroundColor": "#00CC6A",
"borderColor": "#00CC6A",
"data": [0, 23, 51.75, 27, 34, 12]
}]
}
}
}
我做错了什么?
谢谢!! =)
【问题讨论】:
-
this.dataCollection: {有错字(应该是this.dataCollection = {)。 -
我无法重现这个codesandbox中的错误
-
@tony19 我花了 2 天时间来重现错误...我将
{{dataCollection}}用于查看我的数据...这会在控制台中重现错误...我现在的问题是:为什么? D= ...我很困惑。这是一个更新的代码框:codesandbox.io/s/4rwqj8z9nx
标签: javascript vue.js vue-chartjs