使用路由传递信息

0. 需求

在某个页面获得前个页面的东西,因为不是父子级关系,显然就整路由传参比较OK

1. 路由

//$router : 是路由操作对象,只写对象
//$route : 路由信息对象,只读对象

//操作 路由跳转
this.$router.push({
      name:'hello',
      params:{
          name:'word',
          age:'11'
     }
})

//读取 路由参数接收
this.name = this.$route.params.name;
this.age = this.$route.params.age;

2. param与query

使用params传参只能使用name进行引入路径

使用query传参Name path都可以引入路径

所以query使用更广!!!用query就完事了嗷。

3. 小小BUG

created() {
    let deliver = this.$route.query?.deliver;
    if (deliver ?? null) {
      this.queryForm = deliver;
    }
    this.fetchData();
  },

如果直接等于,再次刷新抵达的界面,就会爆红,原因是对象地址指向了1个虚无的东西。这种情况下,记得把传过来的这玩意深拷贝1下就好了。

this.queryForm = Object.assign({}, deliver);

原文地址:https://www.cnblogs.com/lepanyou/p/15597269.html