router和route的區別和使用

router和route 區別:

1、跳轉到當前路由的地址:
              不傳參的形式: this.$router.push('/index')

              直接添加路徑: this.$router.push('/index?from=login')

               query傳參:

this.$router.push({
    path:'/index',
    query:{
      from:'login'     // 參數名稱
    }
})

               params傳參:

this.$router.push({
    path:'index',      // name
    params:{
      from:'login'     // 參數名稱
    }
})

2、獲取當前路由參數: this.$route.params.from

3、獲取當前路由id: this.$route.params.id

4、獲取當前路由地址:this.$route.path

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章