在vue中,使用router-link来跳转页面时,发现params属性并不能获取到,查看官网API发现如果提供了 path
,params
会被忽略,上述例子中的 query
并不属于这种情况。取而代之的是下面例子的做法,你需要提供路由的 name
或手写完整的带有参数的 path
:
<template> <div> <ul> <li v-for="(item,index) in content" :key="index">{{item.title}}</li> <router-link :to="{name:‘second‘,params:{id:123}}">ylz</router-link> </ul> </div> </template>
routes: [ { path: "/", //路径 name: "first",//路由组件名称 component: First //组件 }, { path: ‘/second‘, name: "second", component: Second, children: [ { path: "/second/third", name: "third", component: Third } ] } ]
这样就能很好的解决问题啦
原文:https://www.cnblogs.com/ylzigmy/p/11272576.html