我正在尝试将 Chart.js 与 Vue.js 一起使用,这就是我正在编译的内容,但我没有看到 GUI 上显示任何内容。
这是我的文件 DonutChart.vue:
<template>
// NOT SURE IF SOMETHING SHOULD GO HERE
</template>
<script>
import {Bar} from 'vue-chartjs'
// import the component - chart you need
export default Bar.extend({
mounted () {
// Overwriting base render method with actual data.
this.renderChart({
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
datasets: [
{
label: 'News reports',
backgroundColor: '#3c8dbc',
data: [12, 20, 12, 18, 10, 6, 9, 32, 29, 19, 12, 11]
}
]
},)
}
});
</script>
这是父组件“Usage.vue”:
<template>
<h1>USAGE</h1>
<st-donut-chart></st-donut-chart>
</template>
<script>
import Vue from 'vue';
import Filter from './shared/filter/Filter';
import DonutChart from './DonutChart'
export default new Vue({
name: 'st-usage',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
components: {
'st-filter': Filter,
'st-donut-chart': DonutChart,
}
});
</script>
DonutChart.vue 和 Usage.vue 在同一个目录下: