http://192.168.1.100:8080/#/infoDetailed/231
//定义路由
{ path: "/infoDetailed/:newsId", name: "InfoDetailed", component: () => import("@/views/info/InfoDetailed.vue") },
//a组件传参
http://192.168.1.100:8080/#/infoDetailed?newsId=230
{ path: "/infoDetailed", name: "InfoDetailed", component: () => import("@/views/info/InfoDetailed.vue") } handleEdit(index, row) { console.log(index, row); this.$router.push({ name: "InfoDetailed", query: { newsId: row.id } }); }, created() { this.newsId = this.$route.query.newsId }
以name自定义属性举例子:
不要在params中随便加路由path中未定义的动态路由参数。
另外即使加了name属性,跳转到新的页面url地址http://192.168.1.100:8080/#/infoDetailed/231 也只会携带上newsId的参数信息,不会带上name的数据信息。
handleEdit(index, row) { console.log(index, row); // params参数丢失问题:name在router.js路由path中并没有配置, path: "/infoDetailed/:newsId", //自己强行加进去,跳转到新页面,第一次会存在,但是一旦刷新,name参数直接丢失。而newsId无此问题。 this.$router.push({ name: "InfoDetailed", params: { newsId: row.id,name:‘zs‘ } }); },
原文:https://www.cnblogs.com/xiaoliziaaa/p/13198817.html