javascript - 当我想传递参数时,路由器推送在 vuejs 中不起作用
问题描述
当我想通过vue-router
包使用编程导航时,它可以工作,但是当我想将参数传递给带有router.push
方法的组件时,它根本不起作用。有人有解决方案吗?
我的代码在这里:
import VueRouter from 'vue-router'
import routes from './routes';
const router = new VueRouter({routes});
Vue.use(VueRouter);
和推送代码:
router.push({ name: 'reportArchive', params: {token: token} });
我的路线配置:
{ path: '/reportArchive', name: 'reportArchive', component: reportArchive },
解决方案
如果你真的想传递参数,你需要设置接受参数的路由,如下所示:
{ path: '/reportArchive/:token', name: 'reportArchive', component: reportArchive },
这是按照Eldar上面的回答,但是如果你想传递url查询参数,你需要在代码中使用query而不是params,例如:
router.push({ name: 'reportArchive', query: {token: token} });
推荐阅读
- curl - 如何更好地将 curl 转换为 ansible uri
- python - Tweepy Cursor.items() 无法与 api.retweeters 一起按预期工作
- javascript - 解码前和签名后的 JWT 不同
- sql - SQL:计算具有多个 group by 语句的两列
- c# - System.Reflection.Emit:绑定一个类和一个接口
- r - 选择两年内具有相同组的行
- java - 如何摆脱不必要的(?)代码 - 适应 DRY 原则
- ios - 如何将 UITableView 绑定到列表
在 Xamarin iOS 中使用 MvvmCross - c# - 我怎样才能返回一个对象(即列表
) 来自用 NSubstitute 模拟的对象? - uitextfield - SwiftUI 将图像添加到文本字段的左侧