π» νλ‘μ νΈ/π νμκ°μ
νμ΄μ§π
[Vue.js] λ²νΌ λ‘μ§μ΄ μ λλ‘ λμμ μνλ κ² κ°μ λ, chunk-VZXQDS5F.js?v=5f04997f:2125 [Vue warn]: Data property "idDuplicate" is already defined in Methods.
hyeong._.ing
2025. 8. 20. 14:02
λ²νΌμ΄ λμνμ§ μμ λ,
μ΄λ€ μ€λ₯μΈμ§ μ°Ύμ보μ!
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μ μ°κ²°λ μ½λκ° μμ΄μ κ·Έκ²λ νμΈν΄μ€¬λ€.