VueJS道具没有通过router-link传递给组件

时间:2020-02-24 14:29:27

标签: vue.js

我在VueJS组件中具有以下链接:

 <router-link :to="{ name: 'time', props: { tax: 123, site: site_key }}">Add New Request</router-link>

时间组件具有以下代码,其始终显示默认值,而不是值:

<template>
  <div>t {{ tax }} {{site}}</div>
</template>

<script>
    export default {
        name: "Time",
        props: {
            tax: {
                type: String,
                default: 'Vue!'
            },
            site: {
                type: String,
                default: 'Vue!'
            }

        }
    }
</script>

已编辑

const router = new Router({
  routes: [
    {
      path: '/',
      name:'home',
      component: Home,
    },
    {
      path: '/time',
      name:'time',
      component: Time,
      props: { tax: null, site: null }
    },
  ]
})

1 个答案:

答案 0 :(得分:0)

如Vue Router中所示:

https://router.vuejs.org/guide/essentials/passing-props.html

道具通过params字段传递,就像这样:

<router-link :to="{ name: 'time', params: { tax: 123, site: site_key }}">Add New Request</router-link>

有关您的问题的更多信息,请包含您的router.js文件。