const onClickLogin = () => {
axios
.post(`/api/comm/user/signin`, {
id: id,
password: pw,
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error);
});
};
๋ก๊ทธ์ธ ๊ธฐ๋ฅ์ ์ํํ๋ ํจ์๋ฅผ ์์ฑํ๋๋ฐ, ๊ณ์ get์ด ์ฐํ๋ค.
๋ฌผ์ํ๊ฐ ๋ถ๋ ์ด์ ๋,
HTML ํผ์ด GET ๋ฉ์๋๋ก ์ ์ถ๋๋ฉด, ํผ ํ๋ ๊ฐ์ด ์๋์ผ๋ก ์ฟผ๋ฆฌ ์คํธ๋ง์ผ๋ก ์ถ๊ฐ๋๊ธฐ ๋๋ฌธ์ด๋ค.
const onClickLogin = (event) => {
event.preventDefault();
axios.post(`/api/comm/user/signin`,{
id:id,
password:pw
})
.then((response) => {
console.log(response.data)
})
.catch((error) => {
console.log(error);
});
}
๊ทธ๋์ event.preventDefault(); ์ด๋ถ๋ถ ์ถ๊ฐ. ์ด๋ค ์ด๋ฒคํธ๋ฅผ ๋ช ์์ ์ผ๋ก ์ฒ๋ฆฌํ์ง ์์ ๊ฒฝ์ฐ, ํด๋น ์ด๋ฒคํธ์ ๋ํ ์ฌ์ฉ์ ์์ด์ ํธ์ ๊ธฐ๋ณธ ๋์์ ์คํํ์ง ์๋๋ก ์ง์
https://developer.mozilla.org/ko/docs/Web/API/Event/preventDefault
Event.preventDefault() - Web API | MDN
Event ์ธํฐํ์ด์ค์ preventDefault() ๋ฉ์๋๋ ์ด๋ค ์ด๋ฒคํธ๋ฅผ ๋ช ์์ ์ผ๋ก ์ฒ๋ฆฌํ์ง ์์ ๊ฒฝ์ฐ, ํด๋น ์ด๋ฒคํธ์ ๋ํ ์ฌ์ฉ์ ์์ด์ ํธ์ ๊ธฐ๋ณธ ๋์์ ์คํํ์ง ์๋๋ก ์ง์ ํฉ๋๋ค.
developer.mozilla.org
'Programming > React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React] CRA๋์ Vite๋ก React ์ค์น ๋ฐ ์คํํ๊ธฐ (TypeScript) (2) | 2024.09.27 |
---|---|
[ React ] JWT ํ ํฐ (0) | 2024.08.22 |
[ React, TypeScript ] Notification ํ์ ์๋ฆผ ๋์ฐ๊ธฐ (์ฐฝ์ด ์ต์ํ ๋์ด๋ ๋จ๋ ์๋ฆผ) (1) | 2024.06.13 |
[React] ag-grid์์ columnDef์ useMemo์ valueFormatter (0) | 2024.04.03 |
[ AG-GRID ] ๋ณ๊ฒฝ๋ ๋ฐ์ดํฐ๊ฐ ๊ทธ๋ฆฌ๋์ ๋ฐ๋ก ๋ฐ์๋๊ฒ (0) | 2024.03.11 |