javascript - 无法读取 vue-chartjs 中未定义的属性“reactiveProp”
问题描述
我正在尝试使用一个名为“Vue-Chartjs”的组件来创建一个 LineChart。但是当我尝试使用折线图的演示时。发生错误。我得到:未捕获的类型错误:无法读取未定义的属性“reactiveProp”
我的 line-chart.js:
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins
export default {
extends: Line,
mixins: [reactiveProp],
props: ['options'],
mounted () {
// this.chartData is created in the mixin.
// If you want to pass options please create a local options object
this.renderChart(this.chartData, this.options)
}
}
我的仪表板.vue:
<template>
<div class="small">
<p>Dashboard</p>
<line-chart :chart-data="datacollection"></line-chart>
<button @click="fillData()">Randomize</button>
</div>
</template>
<script>
import LineChart from '../charts/line-chart'
export default {
components:{
LineChart,
},
data () {
return {
datacollection: null
}
},
mounted () {
this.fillData()
},
methods: {
fillData () {
this.datacollection = {
labels: [this.getRandomInt(), this.getRandomInt()],
datasets: [
{
label: 'Data One',
backgroundColor: '#f87979',
data: [this.getRandomInt(), this.getRandomInt()]
}, {
label: 'Data One',
backgroundColor: '#f87979',
data: [this.getRandomInt(), this.getRandomInt()]
}
]
}
},
getRandomInt () {
return Math.floor(Math.random() * (50 - 5 + 1)) + 5
}
}
}
</script>
解决方案
您可以更进一步,从 mixins 中提取 reactiveProp
import { Line, mixins: { reactiveProp } } from 'vue-chartjs'
推荐阅读
- python - 如何处理来自“不透明”迭代器的异常
- python - IndexError:索引超出范围,我在这里做错了什么?
- jenkins - 当 curl 请求返回无效状态代码时,我可以让 jenkins 管道不退出吗
- python - 在特定情况下如何填写缺失值?
- flutter - 标签栏在列表滚动时更改标签标题
- ios - com.crashlytics.mac.error-domain.process-dsym Code=4 "此版本的 OSX 无法执行必要的 dSYM 转换
- c++ - OpenGL矩形莫名占满整个窗口
- azure - 服务器端的 gRPC 连接池
- reactjs - 在 TreeView 中设置选定 TreeItem 的样式
- python - Pandas:如果最后一个非零值 < 0:替换为 0