File tree Expand file tree Collapse file tree 1 file changed +22
-17
lines changed Expand file tree Collapse file tree 1 file changed +22
-17
lines changed Original file line number Diff line number Diff line change 180180 bgColor: ' #F5F8FD' ,
181181 bottomPadding: 30 ,
182182 topPadding: 30
183- },
184- collapse: false
183+ }
185184 }
186185 },
187186 components: {
193192 }
194193 },
195194 created (){
196- bus .$on (' collapse' , msg => {
197- this .collapse = msg;
198- });
199- // 调用renderChart方法对图表进行重新渲染
200- window .addEventListener (' resize' , ()=> {
201- this .$refs .bar .renderChart ();
202- this .$refs .line .renderChart ();
203- })
195+ this .handleListener ();
204196 this .changeDate ();
205197 },
206- watch: {
207- collapse (){
208- setTimeout (() => {
209- this .$refs .bar .renderChart ();
210- this .$refs .line .renderChart ();
211- }, 300 );
212- }
198+ activated (){
199+ this .handleListener ();
200+ },
201+ deactivated (){
202+ window .removeEventListener (' resize' , this .renderChart );
203+ bus .$off (' collapse' , this .handleBus );
213204 },
214205 methods: {
215206 changeDate (){
218209 const date = new Date (now - (6 - index) * 86400000 );
219210 item .name = ` ${ date .getFullYear ()} /${ date .getMonth ()+ 1 } /${ date .getDate ()} `
220211 })
212+ },
213+ handleListener (){
214+ bus .$on (' collapse' , this .handleBus );
215+ // 调用renderChart方法对图表进行重新渲染
216+ window .addEventListener (' resize' , this .renderChart )
217+ },
218+ handleBus (msg ){
219+ setTimeout (() => {
220+ this .renderChart ()
221+ }, 300 );
222+ },
223+ renderChart (){
224+ this .$refs .bar .renderChart ();
225+ this .$refs .line .renderChart ();
221226 }
222227 }
223228 }
You can’t perform that action at this time.
0 commit comments