๋ฒํผ์ด ๋์ํ์ง ์์ ๋,
์ด๋ค ์ค๋ฅ์ธ์ง ์ฐพ์๋ณด์!
1. ์ฝ๋์ ๋ฌธ์ ์ดํผ๊ธฐ
<script> ์ฝ๋ ์ค method ์ผ๋ถ
async idDuplicate() {
try{
const res = await axios.post("http://localhost:8080/api/idDuplicate", {
userId: this.userId
});
alert("์ฌ์ฉ๊ฐ๋ฅํ ์์ด๋์
๋๋ค.");
this.idDuplicate = false;
} catch(e) {
alert(e.response.data);
this.idDuplicate = true;
}
},
์์ด๋์ ์ด๋ฉ์ผ์ ์ค๋ณต ์ฒดํฌํ๋ ๋ฒํผ์ ๋ง๋ค์๋ค. ๋ณด๊ธฐ์ ๋ฌธ์ ๊ฐ ์์ด๋ณด์๋๋ฐ, ๋ฒํผ์ ๋๋ฌ๋ ๋์์ด ์ด๋ค์ง์ง ์์๋ค. ์คํ๋ง ๋ด๋ถ์ ๋ก์ง ๋ฌธ์ ์ผ๊น ์ถ์ด์ ์คํ๋ง๋ ์ฒดํฌ ํด๋ดค์ง๋ง, ๋ฒํผ์ ๋๋ฌ๋ ์คํ๋ง๊น์ง ์์ฒญ์ด ์ค์ง ์์๋ค. ๊ทธ๋ ๋ค๋ฉด vue ์ฝ๋์ ๋ฌธ์ ๊ฐ ์์ด์ ๋ฒํผ ์์ฒด๊ฐ ๋์ํ์ง ์๋๋ค๋ ์๋ฏธ๊ฐ ๋๋ค.
2. ์ฝ์๋ก ๋ฌธ์ ํ์ธํ๊ธฐ
<script> ์ฝ๋ ์ค method ์ผ๋ถ
async idDuplicate() {
/* ์ฝ๋ ์ถ๊ฐ!!!! */
console.log("idDuplicate ๋ฒํผ ํด๋ฆญ๋จ:", this.userId);
try{
const res = await axios.post("http://localhost:8080/api/idDuplicate", {
userId: this.userId
});
alert("์ฌ์ฉ๊ฐ๋ฅํ ์์ด๋์
๋๋ค.");
this.idDuplicate = false;
} catch(e) {
alert(e.response.data);
this.idDuplicate = true;
}
},
๋ฒํผ์ ๋๋ฅด๋ฉด ์ฝ์์ ๋ก๊ทธ๊ฐ ์ฐํ๋๋ก ์ถ๊ฐํ๋ค. ๋ฒํผ์ ๋ฌธ์ ๊ฐ ์์ผ๋, ์ด๋ค ๋ฌธ์ ์ธ์ง ์๋ ค์ค ๊ฒ์ด๋ค.
chunk-VZXQDS5F.js?v=5f04997f:2125 [Vue warn]:
Data property "idDuplicate" is already defined in Methods.
at <BasicRegister onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > > at <RouterView > at <App>
์์ฒญ๋๊ฒ ๊ธด ์๋ฌ ๋ฉ์์ง๊ฐ ๋ด๋ค. ๋ง์ ๋ค์ด๋ณด๋ฉด ๋ฐ์ดํฐ์ธ idDuplicate๊ฐ ์ด๋ฏธ ๋ฉ์๋์ ์ ์๋์๋ค๊ณ ๋งํ๋ ๊ฒ ๊ฐ๋ค. ์ฝ๊ฒ ๋งํด์ data์ method์ ๋์ผํ ์ด๋ฆ์ด ์ ํ์๋ค๋ ๊ฒ! (์ด๋ฉ์ผ๋ ์ค๋ฅ๊ฐ ๋๊ฐ์ด ์ ํ์์๋ค.)
3. ๋ฌธ์ ํด๊ฒฐ
<script>์ data
data() {
return {
name: "",
userId: "",
pwd: "",
pwdConfirm: "",
tel: "",
birth: "",
email: "",
idDuplicate: true,
emailDuplicate: true,
};
},
<script> ์ฝ๋ ์ค method ์ผ๋ถ
async checkIdDuplicate() {
try{
const res = await axios.post("http://localhost:8080/api/idDuplicate", {
userId: this.userId
});
alert("์ฌ์ฉ๊ฐ๋ฅํ ์์ด๋์
๋๋ค.");
this.idDuplicate = false;
} catch(e) {
alert(e.response.data);
this.idDuplicate = true;
}
},
์๊น ๋ฉ์๋๋ช ๋ idDuplicate๋ก ์ ์๊ณ , data์๋ idDuplicate๋ผ๊ณ ์ ์ํ๋ค. ์์์ ๋ฐ์ดํฐ์ ๋ฉ์๋๋ฅผ ๊ตฌ๋ถํ ์ค ์์๋๋ฐ, ๋ชปํ๋๋ณด๋ค... ํด๊ฒฐ๋ฒ์ ์์ฃผ ๊ฐ๋จํ๋ค. ๋ฉ์๋๋ช ์ ๋ฐ๊พธ๊ฑฐ๋ ๋ฐ์ดํฐ๋ช ์ ๋ฐ๊พธ๋ฉด ๋๋ค. ํ์๋ ๋ฉ์๋๋ช ์ checkIdDuplicate๋ก ๋ฐ๊ฟ์คฌ๋ค. ๊ทธ๋ฆฌ๊ณ template์ ์ฐ๊ฒฐ๋ ์ฝ๋๊ฐ ์์ด์ ๊ทธ๊ฒ๋ ํ์ธํด์คฌ๋ค.