动态路由

首页

    // 进入详情
        detail(id){
            console.log("详情")
            this.$router.push({path:'./detail/'+id})
        }   

  //传参 (在 query 里面)
    this.$router.push({path: '/product/buy',    query: {  orders: JSON.stringify(orders)  ,  total: orders[0].totalAmount  ,  stock: this.select  }  })
 
   // 下个页面接收
    
    this.orders = JSON.parse(this.$route.query.orders)

详情页

methods:{
        load(){
            this.getDetail()
            console.log("路由的id")
            console.log(this.$route.params.id)
            this.detailId = this.$route.params.id
        }
    }

$router 和 $route的区别

$router是VueRouter的实例,在script标签中想要导航到不同的URL,使用$router.push方法。

返回上一个历史history用$router.to(-1)

$route为当前router跳转对象。里面可以获取当前路由的name,path,query,parmas

原文地址:https://www.cnblogs.com/ll15888/p/11585606.html