場景:
遇到一個echarts的問題,查了一天的資料,終於解決了!
頁面一開始,圖表能出來,但是切換過頁面后,再回來就不顯示了。之前:

之后:

解決:
echarts的dom元素有一個屬性:_echarts_instance_,它應該類似id,需要每次刷新重新生成。如圖:

vue切換路由的時候,這個屬性一直沒變,因此解決方案如下:
const command_edom = document.getElementById("command"); command_edom.removeAttribute("_echarts_instance_"); this.myChartPie = echarts.init(command_edom); this.myChartPie.setOption(this.commandOption);
可以手動刪除這個屬性,讓它重新生成!
參考:
https://blog.csdn.net/Tsinbo1314/article/details/122977239
https://blog.csdn.net/qq_34645412/article/details/102895827
