我正在用蚂蚁设计制作一个编辑表单,我想从组件中的以下路线获取ID
{
path: '/post/edit/:id',
name: 'edit',
hideInMenu: true,
component: './Post/PostForm'
},
我使用以下功能:
export function getLastPart() {
const parts = window.location.href.split('/');
return parts[parts.length - 1];
}
然后,在组件中,您需要检查最后一部分是否是实际ID。例如,我使用UUID,所以我也使用以下功能:
const uuidReg = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
export function isUuid(path) {
return uuidReg.test(path);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句