javascript
axios params -> fetch query
FaustK
2020. 7. 21. 09:48
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