javascript - 怎么把id放在url中间
问题描述
我已经定义了一个这样的 URL URLT = URL/id/URL
我如何将 id 的实际值放在“id”部分(/id/)中?
function(param: Param) {
return new Promise<boolean>( (resolve, reject) => {
this.http.post<boolean>(URLT+id, options).subscribe( (res => {
resolve(res);
}));
});
}
解决方案
在 Javascript 中,您可以通过不同的方式创建该字符串,例如:
const myUrl = "http://www.api.com/" + id + "/foo"
或更好的一个:
const myUrl = `http://www.api.com/${id}/foo`
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
干杯
推荐阅读
- java - @FunctionalInterface 在分阶段构建器中的好处
- spring-tool-suite - 使用 OpenJDK 11 配置时 Spring Tool Suite 无法打开
- linux - 用于删除除最后 5 个文件夹之外的所有文件夹的 Shell 脚本
- azure - Terraform Azure 在 VM 上运行 bash 脚本
- android - react native 生成的 APK 不会向 Android 9 设备上的服务器发出请求
- c# - asp.net 视图中字符串方法的问题
- reactjs - Reactjs:超过最大更新深度
- big-o - O(n^2) 中但不在 Ω(n^2) 中的函数也在 Ω(n) 中但不在 O(n) 中
- r - 如果 datetime 中的时间是午夜 00:00:00 更改为第二天
- kubernetes - 跨 Kubernetes 主节点的负载均衡