fix[Chart]: fixed chart bug in keep-alive (#2119)

This commit is contained in:
花裤衩
2019-05-23 11:27:10 +08:00
committed by GitHub
parent 8ce250a44e
commit 13c1ecf25c
5 changed files with 68 additions and 54 deletions

View File

@@ -5,11 +5,12 @@
<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import { debounce } from '@/utils'
import resize from './mixins/resize'
const animationDuration = 6000
export default {
mixins: [resize],
props: {
className: {
type: String,
@@ -33,18 +34,11 @@ export default {
this.$nextTick(() => {
this.initChart()
})
this.__resizeHandler = debounce(() => {
if (this.chart) {
this.chart.resize()
}
}, 100)
window.addEventListener('resize', this.__resizeHandler)
},
beforeDestroy() {
if (!this.chart) {
return
}
window.removeEventListener('resize', this.__resizeHandler)
this.chart.dispose()
this.chart = null
},