Hello World...
axios params -> fetch query 본문
axios get params 를 fetch 로는 어떻게 보내야 하는 지 검색을 하다 아래처럼 하면 된다는 것을 알게 되었다.
axios get params
axios
.get('http://coupontest.io/coupon', {
params: {
coupon: 'coupon-data'
}
}).then(.....)
fetch 에서는 아래처럼
var url = new URL('http://coupontest.io/coupon');
var params = { coupon: 'coupon-data' };
url.search = new URLSearchParams(params).toString();
fetch(url)
.then((res) => res.json())
.then((res) => console.log(res))
.catch((err) => console.log(err));
https://stackoverflow.com/questions/35038857/setting-query-string-using-fetch-get-request
Setting query string using Fetch GET request
I'm trying to use the new Fetch API: I am making a GET request like this: var request = new Request({ url: 'http://myapi.com/orders', method: 'GET' }); fetch(request); However, I'm unsure h...
stackoverflow.com
'javascript' 카테고리의 다른 글
await setTimeout (0) | 2023.07.14 |
---|---|
onmouseover & onmouseout 로 이미지 변경하기 (0) | 2020.12.04 |
html, css, javascript 모달창 만들기 (0) | 2020.05.13 |
javaScript Promise 헷갈리는 점 추가 (0) | 2020.02.05 |
es6 promise 예제 만들어보기 (0) | 2020.02.04 |
Comments