[英]VueJS props are not passing to component via router-link
I have the following link in a VueJS component:我在 VueJS 组件中有以下链接:
<router-link :to="{ name: 'time', props: { tax: 123, site: site_key }}">Add New Request</router-link>
The Time component has the following code, its always showing the default, instead of the value: Time 组件具有以下代码,它始终显示默认值,而不是值:
<template>
<div>t {{ tax }} {{site}}</div>
</template>
<script>
export default {
name: "Time",
props: {
tax: {
type: String,
default: 'Vue!'
},
site: {
type: String,
default: 'Vue!'
}
}
}
</script>
EDITED已编辑
const router = new Router({
routes: [
{
path: '/',
name:'home',
component: Home,
},
{
path: '/time',
name:'time',
component: Time,
props: { tax: null, site: null }
},
]
})
As seen in Vue Router :如 Vue Router 所示:
https://router.vuejs.org/guide/essentials/passing-props.htmlhttps://router.vuejs.org/guide/essentials/passing-props.html
Props are passed by the params field, so like this :道具由 params 字段传递,如下所示:
<router-link :to="{ name: 'time', params: { tax: 123, site: site_key }}">Add New Request</router-link>
for a much more insight on your problem, please include your router.js
file.要更深入地了解您的问题,请包含您的
router.js
文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.