首页 > 解决方案 > 将道具传递给路由器链接 - Vue.js

问题描述

我正在尝试为我的路由器链接名称传递道具,但它根本不起作用。我究竟做错了什么?

按钮组件:

<template>
      <router-link :to="{ name: nextStep }" tag="button" class="button">Back</router-link>
      <router-link :to="{ name: previousStep }" tag="button" class="button">Next</router-link>
</template>
<script>
    export default {
        props: {
            nextStep: {
                type: String,
                default: null,
            },
            previousStep: {
                type: String,
                default: null
            }
        },
     
    }
</script>

当我使用组件时

  <Buttons :nextStep="Firststep" :previousStep="Secondstep" />

和我的路由器 js 以确保名称正确

{
    path: "/firststep",
    name: "Firststep",
    component: FirstStep
  },
  {
    path: "/secondstep",
    name: "Secondstep",
    component: SecondStep
  },

标签: javascriptvue.jsvuejs2

解决方案


尝试删除绑定标志:

<Buttons nextStep="Firststep" previousStep="Secondstep" />

如果您使用绑定符号,则应将值定义为属性。


推荐阅读