Vue Nuxt ํ๊ฒฝ์์ ์์
์ ํ๋ค๊ฐ
๋ทฐ์์ ๊ถ๊ณ ํ๋ HTTP ํต์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ธ ์ก์์ค์ค(Axios)๋ฅผ ์ฌ์ฉํ๋ค.
์ฌ์ฉ๋ฒ์ npm install๋ก ์ค์น ํ ์ฌ์ฉํ๋ฉด ๋๋ค.
npm install axios
[error๐จ]
๋ณธ๊ฒฉ์ ์ผ๋ก API๋ฅผ ์ฐ๊ฒฐํ๋ฉด์
axios.post(โurlโ, {payload})๋ก ํธ์ถํ๋๋ฐ, Network Tab์์ ํ์ธํด๋ณด๋
์ํ ์ฝ๋: 302 Found ์๊ณ ,
Redirect๊ฐ ๋๋ฉด์ Get์ผ๋ก ํ ๋ฒ ๋ ์์ฒญ์ด ๋ค์ด๊ฐ๋ค.
(get์ผ๋ก ์์ฒญ์ด ๋ค์ด๊ฐ ์๋ต)
๋ ๋ญ๊ฐ ๋ฌธ์ ์ผ...~~~ํ๋ฉด์ ์ฐพ์๋ณธ 302 Found / 302 Redirect
302 Found:
The HyperText Transfer Protocol (HTTP) 302 Found redirect status response code indicates that the resource requested has been temporarily moved to the URL given by the Location header.
์์ฒญ๋ ๋ฆฌ์์ค๊ฐ ํค๋์ ์ง์ ๋ URL๋ก ์ผ์์ ์ผ๋ก ์ด๋๋์๋ค..?
์..?
๊ทธ๋ผ ๋ญ๊ฐ ๋ฌธ์ ์ธ๊ฑฐ์ง.. ํ๋ฉด์ ์ฐพ์๋ณด๋
[resolve๐ซ]
axios.post(โurlโ, {payload})์์
url์ด ์๋ชป ๋ค์ด๊ฐ๊ณ ์์๋ค...ใ
์์ ํ ๊ธ์๊ฐ ๋น ์ ธ์ ๊ณ์ ์๋ชป๋ ๊ฒฝ๋ก๋ก ์์ฒญ์ด ๋ค์ด๊ฐ๊ณ ์์๋ ๊ฒ!
url๋ง ๋น ๋ฅด๊ฒ ์์ ํด์ฃผ๋๊น ์ ์์ ์ผ๋ก ์์ฒญ์ด ๋ค์ด๊ฐ๊ณ , ์๋ต์ด ์๋ค.
ํญ์ ์ด๋ฐ ์ฌ์ํ ์๋ฌ๊ฐ ๋ ์ฐพ๊ธฐ ํ๋ ๊ฒ ๊ฐ๋ค....๐ค