格式化形如 /data/{id}/abc/{path}的url,结果返回类似/data/1/abc/123

const formatUrl = (url: string, path: object) => {
const reg = new RegExp(/\{(\w+)\}/, "g");
return url.replace(reg, ($0: any, $1: any) => {
return path[$1];
});
};

猜你喜欢

转载自www.cnblogs.com/xuanbingbingo/p/10931521.html
今日推荐