个人记录01-vue中两种路由传参方式

vue中两种简单路由传参方式

methods: {
        buy(id){
            //this.$router.history.push("/buy/"+id)       -地址栏中是这样的http://localhost:8080/buy/id

            // console.log(this.$router);
            this.$router.history.push({
                //这一对是路由跳转传参方式
                name:"buy",
                params:{id} //传参数
              
            })
        },
        gotoDetail(id){
            this.$router.history.push({
                //这又一对是路由跳转传参方式   !!!两种路由传参方式不能弄混
               path:"/detail",
               query:{id,name:"leson"}                 //-地址栏是这样的http://localhost:8080/detail?id=id&name=leson
            })
        },

  通过query传参,接收参数方式

created(){
        let filmId=this.$route.query.id;
        console.log(filmId);
    },
原文地址:https://www.cnblogs.com/setbug/p/14348139.html