Merge pull request #128 from lin-xin/dev

'离开首页时移除监听事件'
pull/195/head
林鑫 2018-09-12 19:37:44 +08:00 committed by GitHub
commit 81f571ec15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 17 deletions

View File

@ -180,8 +180,7 @@
bgColor: '#F5F8FD', bgColor: '#F5F8FD',
bottomPadding: 30, bottomPadding: 30,
topPadding: 30 topPadding: 30
}, }
collapse: false
} }
}, },
components: { components: {
@ -193,23 +192,15 @@
} }
}, },
created(){ created(){
bus.$on('collapse', msg => { this.handleListener();
this.collapse = msg;
});
// renderChart
window.addEventListener('resize', ()=>{
this.$refs.bar.renderChart();
this.$refs.line.renderChart();
})
this.changeDate(); this.changeDate();
}, },
watch: { activated(){
collapse(){ this.handleListener();
setTimeout(() => { },
this.$refs.bar.renderChart(); deactivated(){
this.$refs.line.renderChart(); window.removeEventListener('resize', this.renderChart);
}, 300); bus.$off('collapse', this.handleBus);
}
}, },
methods: { methods: {
changeDate(){ changeDate(){
@ -218,6 +209,20 @@
const date = new Date(now - (6 - index) * 86400000); const date = new Date(now - (6 - index) * 86400000);
item.name = `${date.getFullYear()}/${date.getMonth()+1}/${date.getDate()}` item.name = `${date.getFullYear()}/${date.getMonth()+1}/${date.getDate()}`
}) })
},
handleListener(){
bus.$on('collapse', this.handleBus);
// renderChart
window.addEventListener('resize', this.renderChart)
},
handleBus(msg){
setTimeout(() => {
this.renderChart()
}, 300);
},
renderChart(){
this.$refs.bar.renderChart();
this.$refs.line.renderChart();
} }
} }
} }