可选路由器参数中的 Vue prop 是空字符串而不是默认值

问题描述 投票:0回答:1

我正在尝试将可选参数 clientId 从路由传递到我的组件:

//router.js
{
   path: "/new-services-request/:clientId?",
   name: "NewServicesRequest",
   component: () => import("../views/ServicesRequest/NewServicesRequest.vue"),
   props: true
},

在我的组件中,我有:

//NewServicesRequest.vue
const props = defineProps({
  clientId: {
    type: String,
    required: false,
    default: "0"
  }
});

现在,在我的布局中,当我单击链接

to="/new-services-request"
时,页面会加载,但
props.clientId
是空字符串
""
而不是
"0"
。 有什么帮助吗?

vue.js vuejs3 vue-router
1个回答
0
投票

在这种情况下,您需要显式传递

undefined
null
参数。

<router-link :to="{ name: 'NewServicesRequest', params: { clientId: undefined } }">
© www.soinside.com 2019 - 2024. All rights reserved.