WishMeLz

生活其实很有趣

Vue路由跳转

1. router-link
2. this.$router.push()
3. this.$router.replace() (用法同push)
4. this.$router.go(n)

router-link

<router-link :to="{name:'home'}"> 
<router-link :to="{path:'/home'}"> 

<router-link :to="{name:'home', params: {id:1}}"> 
   类似于post,第一次有效,刷新就消失

<router-link :to="{name:'home', query: {id:1}}"> 
   类似于get,拼接在路劲上

this.$router.push() 

this.$router.push('/home') 
this.$router.push({name:'home'}) 
this.$router.push({path:'/home'})

this.$router.push({
        path:"/",
        query:{
          name:"tom",
          age:20
        }
      })

this.$router.replace() (用法同push)

this.$router.go(n) 
向前或者向后跳转n个页面,n可为正整数或负整数