After entering the chart page, call the get chart data interface. If the interface does not return data, it will jump off the chart page, and then the data will be returned and the chart will be created, but the container element cannot be obtained after jumping off the chart page, so an error is reported and the chart creation fails.
Do not use native js methods to get container elements (eg:
If the chart page is a cache page, and you want the chart to load well after jumping back to the chart page, you need to write the width and height of the container (in
px) in the inline style of the chart container. (Another solution is also provided for cached pages: execute the chart creation method in the
activated life cycle of the component)
<div ref="chinaMapChart" style="width: 770px; height: 560px" /> --- const myChart = echarts.init(this.$refs.chinaMapChart)