有人能为我解释一下我收到的这个评论吗?谢谢。
const path = this.basePath + '/configurations/${id}/LicensePackageInfo'.replace('${' + 'id' + '}', String(id));const = this.basePath + /configurations/${id}/LicensePackageInfo;应该可以。不要使用替换函数,上面的代码使用“字符”替换“替换”函数
发布于 2022-08-30 19:46:39
替换函数接受一个子字符串,并使用该子字符串替换字符串中的每个匹配项。您不需要替换任何内容,URL的格式是正确的。
const path = this.basePath + `/configurations/${id}/LicensePackageInfo`由于一个名为字符串插值的概念而工作。
在JavaScript中,您可以将变量值放入使用backticks wrapping them in the syntax${}创建的字符串中。
const basePath = 'https://google.com'
const id = 10
const path = basePath + `/configurations/${id}/LicensePackageInfo`
console.log(path) // https://google.com/configurations/10/LicensePackageInfoString interpolation example
const id = 10;
console.log(`my id is: ${id}`) //my id is: 10
console.log("my id is: ${id}") //my id is: ${id}阅读更多关于概念https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals的内容
https://stackoverflow.com/questions/73547539
复制相似问题