Use echarts to redraw the picture according to the screen changes. I have been reporting this error for a long time, but I haven’t found the problem
watch: {
option: {
handler() {
this.myEchart = echarts.init(this.$refs.echartsRef)
this.myEchart.setOption(this.option)
// this.mountedEchart()
},
immediate: false
}
},
mounted() {
// this.mountedEchart()
// this.myEchart = echarts.init(this.$refs.echartsRef)
// this.myEchart.setOption(this.option)
//Redrawing when the screen size changes
window.addEventListener('resize', () => {
this.myEchart.resize()
})
},
Because this component is encapsulated by me and needs to listen to the change of option to redraw the diagram, the init diagram is displayed in the watch
Later, I initialized seals. Init() in both watch and mounted, and this error was solved.
watch: {
option: {
handler() {
// this.myEchart = echarts.init(this.$refs.echartsRef)
// this.myEchart.setOption(this.option)
this.mountedEchart()
},
immediate: false
}
},
mounted() {
this.mountedEchart()
// this.myEchart = echarts.init(this.$refs.echartsRef)
// this.myEchart.setOption(this.option)
//Redrawing when the screen size changes
window.addEventListener('resize', () => {
this.myEchart.resize()
})
},
methods: {
mountedEchart() {
this.myEchart = echarts.init(this.$refs.echartsRef)
this.myEchart.setOption(this.option)
}
},
However, another warning appears charts.js?1be7:2178 There is a chart instance already initialized on the dom.
After unremitting efforts, I finally found the problem. I still didn’t understand the grammar well and didn’t pay attention to the warning itself. In fact, the problem is the same as the warning. The ecarts instance already exists
I registered again when the instance existed
ecarts.init (this.$refs.Ecartsref)
runs twice, and all warnings appear
In fact, just redraw the icon and reset setoption. There is no need to register again
watch: {
option: {
handler() {
this.mountedEchart()
}
}
},
mounted() {
this.myEchart = echarts.init(this.$refs.echartsRef)
this.mountedEchart()
// this.myEchart.setOption(this.option)
//Redrawing when the screen size changes
window.addEventListener('resize', () => {
this.myEchart.resize()
})
},
methods: {
mountedEchart() {
// this.myEchart = echarts.init(this.$refs.echartsRef)
//Redraw as long as setOption on it, no need to init again, again init will appear but another warning
//`echarts.js?1be7:2178 There is a chart instance already initialized on the dom.`
this.myEchart.setOption(this.option)
}
},
Similar Posts:
- [Solved] echart Error: Can’t get dom width or height
- ECharts Error: Uncaught Error: `setOption` should not be called during main process
- Pie Component carousel Error: Instance ec_1623382451382 has been disposed (Error-Loading Change Redraw)
- [Solved] TypeError: Cannot read property ‘getAttribute’ of undefined
- [Solved] Vue Import echarts error: Error in mounted hook: “TypeError: Cannot read property ‘init’ of undefined”
- How to Solve Linux resize2fs error: Bad magic number in super-block
- How to Solve Vue Import Chinese Map & Echarts Import China Error
- [Solved] Vue Import echarts Error: export ‘default‘ (imported as ‘echarts‘) was not found in ‘echarts‘
- Next (react) framework combined with lib-flexible, postcss-pxtorem do pc-side rem adaptation to solve the font-size is always 54px issue
- [Solved] vue-pdf Cannot read properties of undefined (reading ‘catch’)