forked from AkkomaGang/admin-fe
perf[Charts]: add resize mixin
This commit is contained in:
parent
a633729215
commit
c398ee0ddc
4 changed files with 21 additions and 1 deletions
|
@ -4,8 +4,10 @@
|
|||
|
||||
<script>
|
||||
import echarts from 'echarts'
|
||||
import resize from './mixins/resize'
|
||||
|
||||
export default {
|
||||
mixins: [resize],
|
||||
props: {
|
||||
className: {
|
||||
type: String,
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
<script>
|
||||
import echarts from 'echarts'
|
||||
import resize from './mixins/resize'
|
||||
|
||||
export default {
|
||||
mixins: [resize],
|
||||
props: {
|
||||
className: {
|
||||
type: String,
|
||||
|
|
|
@ -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) {
|
||||
|
|
15
src/components/Charts/mixins/resize.js
Normal file
15
src/components/Charts/mixins/resize.js
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue