Vue路由的一些知识点

总结几个有关路由的知识点

$router$route的关系

$route为当前router跳转对象里面可以获取namepathqueryparams

$routerVueRouter实例,想要导航到不同URL,则使用$router.push方法等

<router-link>中的to:to 的区别

to是指直接跳转页面 <router-link to="aa>go</router-link">

:to是指跳转时候传参<router-link :to="{path:'tt',query:{'cc':'cc'}}">go </router-link>

跳转时候传参

一种是name的方式 一种是path的方式

方式一 path方式 参数放在query里面

  // 当前是a页面 想传值到 b页面
  <template>
      <div class="me">
          <router-link :to="{path:'go',query:{'cc':'this is cc'}}">
              go 
          </router-link>
      </div>
  </template>
  <script>
      export default{
      
      }
  </script>
  <style scoped lang="less">
      
  </style>
  
  // 路由配置页面
  import Vue from 'vue'
  import Router from 'vue-router'
  Vue.use(Router)
  
  import BB from '../components/bb/bb.vue'
  
  Vue.use(Router)
  
  export default new Router({
      routes: [
          {
              path:'/go',
              // name:'tt',
              component:BB
          }
      ]
  })
  
  // b页面
  <template>
      <div class="test">
          {{$route.query.cc}} // this is cc
      </div>
  </template>
  <script>
      export default {
  
      }
  </script>
  <style scoped lang="less">
      
  </style>

方式二 name方式 参数放在params里面

  // 当前是a页面 想传值到 b页面
  <template>
      <div class="me">
          <router-link :to="{name:'go',params:{'cc':'this is cc'}}">
              go 
          </router-link>
      </div>
  </template>
  <script>
      export default{
      
      }
  </script>
  <style scoped lang="less">
      
  </style>
  
  // 路由配置页面
  import Vue from 'vue'
  import Router from 'vue-router'
  Vue.use(Router)
  
  import BB from '../components/bb/bb.vue'
  
  Vue.use(Router)
  
  export default new Router({
      routes: [
          {
              path:'',
              name:'go',
              component:BB
          }
      ]
  })
  
  // b页面
  <template>
      <div class="test">
          {{$route.params.cc}} // this is cc
      </div>
  </template>
  <script>
      export default {
  
      }
  </script>
  <style scoped lang="less">
      
  </style>

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值