酒钢三中贴吧,private bt 欧美,熊宏博
如果在 vue 组件的 beforerouteenter 钩子函数中调用 api 请求,会出现循环执行的问题:
1 beforerouteenter(to, from, next) { 2 login().then(() => { 3 next({ name: 'home' }); 4 }).catch(() => { 5 next(); 6 }); 7 }, 8
上面的代码会出现无限循环调用的问题,可能是api还没有请求完成,又一次进入 router,调用了 beforrouterenter 的原因,解决办法加一个变量,在调用api之前判断一下:
1 let request = false; 2 3 beforerouteenter(to, from, next) { 4 if (request) { 5 next(); 6 return; 7 } 8 9 request = true; 10 login().then(() => { 11 next({ name: 'home' }); 12 }); 15 }, 16
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
怎么理解wx.navigateTo的events参数使用详情
微信jssdk踩坑之签名错误invalid signature
网友评论