Problem screenshot: the reason for
Cause: After entering the chart page and calling the Get Chart Data interface, the interface jumps away from the chart page before returning the data, and then the data is returned and the chart is created, but after jumping away from the chart page, the container element is not available, so an error is reported and the chart creation fails.
Solution:
1. Instead of using the native js method to get the container element (e.g. document.getElementById()), use this.$refs instead.
2. If the chart page is a cached page and you want the chart to load after jumping back to the chart page, you need to write the width and height of the container (in px) in the in-line style of the chart container. (For cached pages there is also another solution: execute the create chart method in the activated life cycle of the component)
<div ref="chinaMapChart" style="width: 770px; height: 560px" />
------
const myChart = echarts.init(this.$refs.chinaMapChart)
Read More:
- [Solved] echarts Draw Errror: echarts-d9fd185e.js:31447 Uncaught (in promise) Error: Initialize failed: invalid dom.
- [Solved] Vue echarts Error: Initialize failed: invalid dom.
- [Solved] echarts Error: Error in callback for watcher “chartSource“: “Error: Initialize failed: invalid dom.“
- Vue: initialize failed: invalid DOM [How to Solve]
- How to Solve the error: initialize failed invalid dom
- [Solved] Turf.js error: uncaught (in promise) error: the solution of invalid unit
- [Solved] vue-roter 4 Error: Error: Invalid route component/Uncaught (in promise) Error: Invalid route component
- [Solved] Uncaught (in promise) DOMException: Failed to load because no supported source was found.
- How to solve Uncaught (in promise) error in VUE?
- Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to crrent location: “/home“
- How to Solve Uncaught (in promise) Error (Two Solutions)
- [Solved] Uncaught (in promise) Error: Avoided redundant navigation to current location:
- [Solved] Uncaught (in promise) TypeError: XXX.a is not a constructor
- Vue Error: Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location
- ArcGIS API for JavaScript Error Uncaught(in promise): TypeError: xxx is not a constructor
- request.js?b775:101 Uncaught (in promise) Error: Failed to convert value of type ‘java.lang.String’ to required type ‘java.lang.Long’;
- Vue-echarts error: was not found in vue-demi [How to Solve]
- Echarts Map Error: Error: Invalid geoJson format Cannot read property ‘length‘ of undefined
- The addition, deletion and modification of DOM in JS Foundation
- [Solved] Uncaught SyntaxError: Invalid Unicode escape sequence