日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達者為師

網(wǎng)站首頁 編程語言 正文

組件內(nèi)路由守衛(wèi)beforeRouteEnter和beforeRouteLeave

作者:頑強的小豆子 更新時間: 2022-07-10 編程語言
從home.vue組件跳轉(zhuǎn)到news.vue組件調(diào)用beforeRouteEnter,離開news.vue組件調(diào)用beforeRouteLeave
<template>
  <ul>
    <li>news001 <input type="text"></li>
    <li>news002 <input type="text"></li>
    <li>news003 <input type="text"></li>
  </ul>
</template>


<script>
  export default {
    name:'News',
    data() {
      return {
      }
    },
    //進入該組件進行攔截
    beforeRouteEnter(to,from,next){
      if(to.meta.isAuth){
        if(localStorage.getItem("username") === "yaomm"){
          next()
        }else{
          next("/login")
        }
      }else{
        next()
      }
    },
    //離開news頁面時執(zhí)行
    beforeRouteLeave(to, from, next){
      console.log("守衛(wèi)完成",to)
      //如果沒有next()無法離開news頁面
      next()
    }
  }
</script>

原文鏈接:https://blog.csdn.net/qiuyushuofeng/article/details/124846813

欄目分類
最近更新