我有一个 vue-router 应用程序,它没有接收我传递的参数,这是我的组件代码
<template>
<div id="container">
<section class="content" id="error-display">
<div class="row">
<div class="col-sm-12">
<article class="col-sm-offset-1 col-sm-3">
<img src="images/smurf.png" alt="Smurf - Grouchy">
</article>
<article class="col-sm-7">
<h1>{{ $route.params.code }}</h1>
<p>{{ $route.params.message }}, Go back <a href="#">home</a></p>
</article>
</div>
</div>
</section>
</div>
这是我的 vue-router 的声明
const router = new VueRouter({
routes: [
{ path: '/error', component: { template: '<error></error>' } }
]
});
这是我用来导航的代码
router.push({ path: 'error', params: { code: 404, message: 'Resources not found' } })
我错过了什么还是我做错了什么?因为参数被渲染为空。提前致谢
您没有为路线定义参数。
像这样的路由{ path: '/error/:code/:message', component: { template: '<error></error>' } }
应该可以工作,但在这种情况下值得考虑使用查询而不是参数,因为它/error/404/Resources%20not%20found
是一个奇怪的 URL。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句