Front-End-URL-Übergabeparameter

1. Standort

window.location.replace(`${
      
      window.location.origin}?a=${
      
      record.a}&b=${
      
      record.b}&c=${
      
      record.c}`)
      let result = new Object();
      //获取?的位置
      const url = document.location.href
      const index = url.indexOf("?")
      if (index != -1) {
    
    
        //截取出?后面的字符串
        const str = url.substr(index + 1);
        //将截取出来的字符串按照&变成数组
        const strs = str.split("&");
        //将get传参存入对象中
        for (let i = 0; i < strs.length; i++) {
    
    
          result[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
        }
      }
	this.a= result.a
	this.b= result.b
	this.c= result.c

2. Router

2.1 Parameter

Parameter sind Teil der Route. Wenn die Route über Parameterparameter verfügt, dieser Parameter jedoch während des Sprungs nicht übergeben wird, schlägt der Sprung fehl oder die Seite hat keinen Inhalt.

      this.$router.push({
    
    
        name: 'xxxx',
        params: {
    
    
          a: record.a,
          b: record.b,
          c: record.c
        }
      })   
      this.a= this.$route.params.a
      this.b= this.$route.params.b
      this.c= this.$route.params.c

2.1 Abfrage

      this.$router.push({
    
     path: `/x/xx/xxx/xxxx?a=${
      
      record.a}&b=${
      
      record.b}&c=${
      
      record.c}` });
      this.$router.push({
    
    
        path: '/xxxx',
        query: {
    
    
          a: record.a,
          b: record.b,
          c: record.c
        }
      })  
 	  this.a= this.$route.query.a
 	  this.b= this.$route.query.b
 	  this.c= this.$route.query.c

Supongo que te gusta

Origin blog.csdn.net/q249859693/article/details/126827210
Recomendado
Clasificación