Skip to content

Commit

Permalink
fix[Charts]: fixed charts resize mixins bug PanJiaChen#1285 (PanJiaCh…
Browse files Browse the repository at this point in the history
  • Loading branch information
LarchLiu authored and PanJiaChen committed Nov 2, 2018
1 parent 1d684b7 commit 1701fcc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/components/Charts/mixins/resize.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { debounce } from '@/utils'

export default {
data() {
return {
sidebarElm: null
}
},
mounted() {
this.__resizeHandler = debounce(() => {
if (this.chart) {
Expand All @@ -9,14 +14,13 @@ export default {
}, 100)
window.addEventListener('resize', this.__resizeHandler)

const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
sidebarElm.addEventListener('transitionend', this.sidebarResizeHandler)
this.sidebarElm = document.getElementsByClassName('sidebar-container')[0]
this.sidebarElm && this.sidebarElm.addEventListener('transitionend', this.sidebarResizeHandler)
},
beforeDestroy() {
window.removeEventListener('resize', this.__resizeHandler)

const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
sidebarElm.removeEventListener('transitionend', this.sidebarResizeHandler)
this.sidebarElm && this.sidebarElm.removeEventListener('transitionend', this.sidebarResizeHandler)
},
methods: {
sidebarResizeHandler(e) {
Expand Down
10 changes: 5 additions & 5 deletions src/views/dashboard/admin/components/LineChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export default {
},
data() {
return {
chart: null
chart: null,
sidebarElm: null
}
},
watch: {
Expand All @@ -55,8 +56,8 @@ export default {
}
// 监听侧边栏的变化
const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
sidebarElm.addEventListener('transitionend', this.sidebarResizeHandler)
this.sidebarElm = document.getElementsByClassName('sidebar-container')[0]
this.sidebarElm && this.sidebarElm.addEventListener('transitionend', this.sidebarResizeHandler)
},
beforeDestroy() {
if (!this.chart) {
Expand All @@ -66,8 +67,7 @@ export default {
window.removeEventListener('resize', this.__resizeHandler)
}
const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
sidebarElm.removeEventListener('transitionend', this.sidebarResizeHandler)
this.sidebarElm && this.sidebarElm.removeEventListener('transitionend', this.sidebarResizeHandler)
this.chart.dispose()
this.chart = null
Expand Down

0 comments on commit 1701fcc

Please sign in to comment.