perf[Charts]: add resize mixin

This commit is contained in:
Pan 2018-03-13 18:36:11 +08:00
parent a633729215
commit c398ee0ddc
4 changed files with 21 additions and 1 deletions

View file

@ -4,8 +4,10 @@
<script>
import echarts from 'echarts'
import resize from './mixins/resize'
export default {
mixins: [resize],
props: {
className: {
type: String,

View file

@ -4,8 +4,10 @@
<script>
import echarts from 'echarts'
import resize from './mixins/resize'
export default {
mixins: [resize],
props: {
className: {
type: String,

View file

@ -4,8 +4,10 @@
<script>
import echarts from 'echarts'
import resize from './mixins/resize'
export default {
mixins: [resize],
props: {
className: {
type: String,
@ -31,7 +33,6 @@ export default {
},
mounted() {
this.initChart()
this.chart = null
},
beforeDestroy() {
if (!this.chart) {

View file

@ -0,0 +1,15 @@
import { debounce } from '@/utils'
export default {
mounted() {
this.__resizeHanlder = debounce(() => {
if (this.chart) {
this.chart.resize()
}
}, 100)
window.addEventListener('resize', this.__resizeHanlder)
},
beforeDestroy() {
window.removeEventListener('resize', this.__resizeHanlder)
}
}