首页 > 解决方案 > 怎么把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);
      }));
    });
  }

标签: javascriptnode.js

解决方案


在 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

干杯


推荐阅读