import echarts from 'echarts'; export default { data() { return { chartInstance: null, }; }, mounted() { this.initChart(); }, methods: { initChart() { const chartContainer = this.$refs.chartContainer; this.chartInstance = echarts.init(chartContainer); const option = { // 配置选项 }; this.chartInstance.setOption(option); window.addEventListener('resize', this.resizeChart); }, resizeChart() { if (this.chartInstance) { this.chartInstance.resize(); } }, }, beforeDestroy() { window.removeEventListener('resize', this.resizeChart); }, }; .chart-container { width: 100%; height: 400px; }