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> <script>
import echarts from 'echarts' import echarts from 'echarts'
import resize from './mixins/resize'
export default { export default {
mixins: [resize],
props: { props: {
className: { className: {
type: String, type: String,

View File

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

View File

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