場(chǎng)景:當(dāng)B頁(yè)面無(wú)數(shù)據(jù)時(shí)家淤,有定時(shí)3s后,自動(dòng)跳轉(zhuǎn)到上一頁(yè)面瑟由,手動(dòng)后退后絮重,會(huì)自動(dòng)轉(zhuǎn)到上上頁(yè)面。
方案:beforeRouteLeave()? ? 導(dǎo)航離開(kāi)該組件的對(duì)應(yīng)路由時(shí)調(diào)用? // 可以訪問(wèn)組件實(shí)例 `this`
beforeRouteLeave(to, from, next) {
? ? //可以寫(xiě)離開(kāi)時(shí)取消倒計(jì)時(shí)
? ? next();
? },
場(chǎng)景:進(jìn)入B頁(yè)面后歹苦,要根據(jù)進(jìn)入的路由青伤,后退到相應(yīng)的來(lái)源頁(yè)面。
方案: 記錄來(lái)源
beforeRouteEnter(to,from ,next){
? ? ?//不能暂氯!獲取組件實(shí)例 `this`
? ? ? ? next(vm=>{
? ? ? ? ? ? vm.froms=from;
? ? ? ? })
},