Vue opens a new window to pass parameters (idea: window.open)

 1. Vue jumps to the page to open a new window, the method of passing parameters

//情况一:传递的是一个参数
let pathHerf = this.$router.resolve({
  path:'/shopping/detail', // 你自己要跳转的路径
  query:{
         Id:this.id,  // query 要传递携带的参数,如:当前传递的是所需id
        }
 })
 window.open(pathHerf.href, '_blank');
 //新页面接收参数:
 在生命周期created(){
                      let shoppingId = this.$route.query.Id
                    }  

//情况二:传递的是一个复杂的数组或者对象
let pathHerf = this.$router.resolve({
  path:'/shopping/detail', // 你自己要跳转的路径
  query:{
         param:JSON.stringify(this.list)  //其中list是一个数组或者对象
        }
 })
 window.open(pathHerf.href, '_blank');
     
//新页面接收参数:
在生命周期created(){
                    let shoppingList = JSON.parse(this.$route.query.param)
                  }

 2. Vue is on the current page, jump to the new route to pass parameters

this.$router.push({
        path: "/shopping/detail",    // 你自己要跳转的路径
        query: { 
                  param: this.list  // query 要传递携带的参数,如:当前传递的是所需id
               }
 });

接收参数方式:
//新页面接收参数:
在生命周期created(){
                    let shoppingList = this.$route.query.param
                  }

Guess you like

Origin blog.csdn.net/m0_69257679/article/details/131026893