在发送请求时,将参数拼接在URL后面,格式为?key1=value1&key2=value2...。例如:
let currentPage = 0;
let pageSize = 18;
fetch(`http://example.com/api/data?currentPage=${currentPage}&pageSize=${pageSize}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
在上面的示例中,将currentPage和pageSize参数拼接在URL的末尾,并使用fetch方法发送请求。收到响应后,将其转换为JSON格式并输出数据,如果出现错误,则输出错误消息。
上一篇:不明白如何实现.map()