//安装和引入Vue及相关库 npm install vue vue-chartjs //引入 import Vue from 'vue' import VueChartJs from 'vue-chartjs' Vue.use(VueChartJs) //创建一个简单的数据可视化组件 <template> <div> <canvas id="bar-chart"></canvas> </div> </template> <script> export default { mounted() { this.renderChart() }, methods: { renderChart() { this.$nextTick(() => { const ctx = document.getElementById('bar-chart').getContext('2d') new Chart(ctx, { type: 'bar', data: { labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], datasets: [{ label: 'Sales', data: [40, 32, 60, 55, 70, 48, 80], backgroundColor: '#42b983' }] }, options: {} }) }) } } } </script>