[请给我一个有关如何使用此方法的示例,因为我有点迷茫(Vanilla JS)
提前感谢。
var id = 3000;
fetch('http://localhost:3000/' + id)
.then(res => res.json())
.then(function (data) {
// handle success
console.log(data);
});
var id = 3000;
axios.get('http://localhost:3000/' + id)
.then(function (response) {
// handle success
console.log(response.data);
});
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
PS:您也可以使用http://localhost:3000/${id}
作为网址字符串。需要使用tilda(`)代替单(')或双(“)字符串!
只需以这种方式在url中提供ID,以便发布或放置,您可以将正文作为第二个参数发送。
axios.get('http://localhost:3000/'+id).then(response=>{
console.log(response.data)}).catch(err=>console.log(err);