1.動態循環id
<div v-for="(item,index) in chartList" :key="index">
<div :id="`chart${index}`"></div>
</div>
2.js部分
this.chartList = res.data.data.chartList;//從后台獲取數據 if (this.chartList.length > 0) { this.$nextTick(() => { this.initChart() }) }
initChart() { this.chartList.forEach((val, index) => { const myChart = this.$echarts.init( document.getElementById(`chart${index}`)) //注意this.chartList[index]這是我們后台拼好數據直接set就行了 myChart.setOption(this.chartList[index]) }) } },
參考於:https://www.jianshu.com/p/a7af5814efd9