Skip to content

Commit

Permalink
'离开首页时移动监听事件'
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-xin committed Sep 12, 2018
1 parent 8b9aca0 commit 6ac7296
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/components/page/Dashboard.vue
Expand Up @@ -180,8 +180,7 @@
bgColor: '#F5F8FD',
bottomPadding: 30,
topPadding: 30
},
collapse: false
}
}
},
components: {
Expand All @@ -193,23 +192,15 @@
}
},
created(){
bus.$on('collapse', msg => {
this.collapse = msg;
});
// 调用renderChart方法对图表进行重新渲染
window.addEventListener('resize', ()=>{
this.$refs.bar.renderChart();
this.$refs.line.renderChart();
})
this.handleListener();
this.changeDate();
},
watch: {
collapse(){
setTimeout(() => {
this.$refs.bar.renderChart();
this.$refs.line.renderChart();
}, 300);
}
activated(){
this.handleListener();
},
deactivated(){
window.removeEventListener('resize', this.renderChart);
bus.$off('collapse', this.handleBus);
},
methods: {
changeDate(){
Expand All @@ -218,6 +209,20 @@
const date = new Date(now - (6 - index) * 86400000);
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();
}
}
}
Expand Down

0 comments on commit 6ac7296

Please sign in to comment.