fix: 优化页面销毁时对echarts实例的销毁

This commit is contained in:
刘洪洪
2023-01-11 18:11:43 +08:00
parent 8cb3f00aa4
commit bd1eeec770
10 changed files with 35 additions and 8 deletions

View File

@@ -95,6 +95,9 @@ export default {
},
beforeUnmount () {
window.removeEventListener('resize', this.resize)
if (this.myChart) {
echarts.dispose(this.myChart)
}
}
}
</script>

View File

@@ -147,6 +147,9 @@ export default {
},
beforeUnmount () {
window.removeEventListener('resize', this.resize)
if (this.myChart) {
echarts.dispose(this.myChart)
}
}
}
</script>

View File

@@ -567,7 +567,9 @@ export default {
beforeUnmount () {
clearTimeout(this.timer)
window.removeEventListener('resize', this.resize)
this.myChart = null
if (this.myChart) {
echarts.dispose(this.myChart)
}
this.chartOption = null
this.unitConvert = null
}

View File

@@ -456,7 +456,9 @@ export default {
beforeUnmount () {
clearTimeout(this.timer)
window.removeEventListener('resize', this.resize)
this.myChart = null
if (this.myChart) {
echarts.dispose(this.myChart)
}
this.chartOption = null
this.unitConvert = null
}

View File

@@ -734,7 +734,9 @@ export default {
window.removeEventListener('resize', this.resize)
clearTimeout(this.timerScroll)
clearTimeout(this.timerSearch)
this.myChart = null
if (this.myChart) {
echarts.dispose(this.myChart)
}
this.unitConvert = null
}
}

View File

@@ -703,7 +703,9 @@ export default {
if (myChart) {
echarts.dispose(myChart)
}
this.myChart = null
if (this.myChart) {
echarts.dispose(this.myChart)
}
// 检测时发现该方法占用较大内存,且未被释放
this.unitConvert = null
myChart = null

View File

@@ -193,6 +193,14 @@ export default {
beforeUnmount () {
clearTimeout(this.timer)
window.removeEventListener('resize', this.resize)
const dom = document.getElementById('chart1')
const dom2 = document.getElementById('chart2')
if (dom) {
echarts.dispose(dom)
}
if (dom2) {
echarts.dispose(dom2)
}
this.myChart = null
this.myChart2 = null
}

View File

@@ -152,7 +152,9 @@ export default {
},
beforeUnmount () {
window.removeEventListener('resize', this.resize)
this.myChart = null
if (this.myChart) {
echarts.dispose(this.myChart)
}
this.chartOption = null
}
}

View File

@@ -336,7 +336,9 @@ export default {
beforeUnmount () {
clearTimeout(this.timer)
window.removeEventListener('resize', this.resize)
this.myChart = null
if (this.myChart) {
echarts.dispose(this.myChart)
}
this.chartOption = null
}
}

View File

@@ -633,8 +633,9 @@ export default {
beforeUnmount () {
clearTimeout(this.timer)
window.removeEventListener('resize', this.resize)
this.myChart = null
this.myChart = null
if (this.myChart) {
echarts.dispose(this.myChart)
}
this.unitConvert = null
}
}