fix[Charts]: fix charts resize in keep-alive bug

This commit is contained in:
花裤衩 2020-01-08 17:59:42 +08:00
parent 088f64eecc
commit e138bbe9c1
1 changed files with 28 additions and 12 deletions

View File

@ -7,20 +7,17 @@ export default {
}
},
mounted() {
this.__resizeHandler = debounce(() => {
if (this.chart) {
this.chart.resize()
}
}, 100)
window.addEventListener('resize', this.__resizeHandler)
this.$_sidebarElm = document.getElementsByClassName('sidebar-container')[0]
this.$_sidebarElm && this.$_sidebarElm.addEventListener('transitionend', this.$_sidebarResizeHandler)
this.initListener()
},
activated() {
this.resize()
this.initListener()
},
beforeDestroy() {
window.removeEventListener('resize', this.__resizeHandler)
this.$_sidebarElm && this.$_sidebarElm.removeEventListener('transitionend', this.$_sidebarResizeHandler)
this.destroyListener()
},
deactivated() {
this.destroyListener()
},
methods: {
// use $_ for mixins properties
@ -29,6 +26,25 @@ export default {
if (e.propertyName === 'width') {
this.__resizeHandler()
}
},
initListener() {
this.__resizeHandler = debounce(() => {
this.resize()
}, 100)
window.addEventListener('resize', this.__resizeHandler)
this.$_sidebarElm = document.getElementsByClassName('sidebar-container')[0]
this.$_sidebarElm && this.$_sidebarElm.addEventListener('transitionend', this.$_sidebarResizeHandler)
},
destroyListener() {
window.removeEventListener('resize', this.__resizeHandler)
this.$_sidebarElm && this.$_sidebarElm.removeEventListener('transitionend', this.$_sidebarResizeHandler)
},
resize() {
if (this.chart) {
this.chart.resize()
}
}
}
}