问题描述
我在下面有这个获取请求,以及变量 data_type 和 data_subtype。我想分别在 :type 和 :subtype 的位置传递 data_type 和 data_subtype 的值,而不实际在那里写入变量值。
fetch('http://localhost:3000/feature/type/:type/subtype/:subtype,{
method: 'GET',headers: {
'Content-Type': 'application/json'
}
}).then(response => response.text())
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
解决方法
您可以替换为 URL 中的变量值。 例如。
join
,
作为扩展@junkie 答案,您应该将您的 url 请求放在字符串文字中,以便您可以使用变量来有条件地替换值,而无需在其中实际写入值,因此只需定义和替换它们。