Vue3 - ynjch97/YNJCH_WIKI GitHub Wiki
- ๋ชจ๋ Vue.js ์ฑ์ Vue๋ฅผ ์ฌ์ฉํ์ฌ ๋ฃจํธ Vue ์ธ์คํด์ค๋ฅผ ์์ฑํ์ฌ ๋ถํธ์คํธ๋ฉ ๋จ
- Instance๋ Vue.js ๋ก ํ๋ฉด์ ๊ฐ๋ฐํ๊ธฐ ์ํด ๊ผญ ์์ฑํด์ผ ํ๋ ํ์ ๋จ์
-
new Vue({...})
๋ก ์ ์ธํ์ฌ ๋ง๋ค์ด์ง ๊ฐ์ฒด๋ฅผ Vue ์ธ์คํด์ค๋ผ๊ณ ํจ
<script>
new Vue({
// instance ์์ฑ
// instance option properties
});
</script>
์ปดํฌ์ง์ (Composition) API๋ ์ปดํฌ๋ํธ ๋ด์์ ์ฌ์ฉํ๋ ํน์ ๊ธฐ๋ฅ์ ๊ฐ๋ ์ฝ๋๋ฅผ ์ ์ฐํ๊ฒ ๊ตฌ์ฑํ์ฌ ์ฌ์ฉํ ์ ์๋๋ก Vue3 ๋ฒ์ ์ ์ถ๊ฐ๋ ํจ์ ๊ธฐ๋ฐ์ API์ด๋ค. ์ปดํฌ๋ํธ API๊ฐ ์๊ธด ์ด์ ๋ Vue๋ ํ๋ก์ ํธ ๊ท๋ชจ๊ฐ ์ปค์ง์๋ก ๊ด๋ฆฌํ๊ธฐ ํ๋ ๋จ์ ๊ณผ ์ปดํฌ๋ํธ์ ๊ณ์ธต๊ตฌ์กฐ๊ฐ ๋ณต์กํ ์๋ก ์ฝ๋์ ๋ํ ์ถ์ ๋ฐ ๊ด๋ฆฌ๊ฐ ํ๋ ์ ์ ๋ณด์ํ๊ธฐ ์ํด ๋ฑ์ฅํ๊ฒ ๋์๋ค.
-
beforeCreate
๋ฐcreated
(setup() ๋ฉ์๋ ์์ฒด๋ก ๋์ฒด๋จ)๋ฅผ ์ ์ธํ๊ณ ์ค์ ๋ฉ์๋์์ ์ก์ธ์คํ ์ ์๋ ์ต์ API Lifecycle Hooks ์ค 9๊ฐ-
onBeforeMount
: mounting์ด ์์๋๊ธฐ ์ ์ ํธ์ถ -
onMounted
: ์ปดํฌ๋ํธ๊ฐ mount๋ ๋ ํธ์ถ -
onBeforeUpdate
: ๋ฐ์ํ ๋ฐ์ดํฐ๊ฐ ๋ณ๊ฒฝ๋ ๋์ re-render๋๊ธฐ ์ ์ ํธ์ถ -
onUpdated
: re-render๋ ํ์ ํธ์ถ -
onBeforeUnmount
: Vue ์ธ์คํด์ค๊ฐ ํ๊ดด(์ญ์ )๋๊ธฐ ์ ์ ํธ์ถ -
onUnmounted
: ์ธ์คํด์ค๊ฐ ํ๊ดด(์ญ์ )๋ ํ ํธ์ถ๋จ -
onActivated
: ๋ณด๊ด๋ ๊ตฌ์ฑ ์์๊ฐ ํ์ฑํ๋๋ฉด ํธ์ถ -
onDeactivated
: ๋ณด๊ด๋ ๊ตฌ์ฑ ์์๊ฐ ๋นํ์ฑํ๋๋ฉด ํธ์ถ -
onErrorCaptured
: ํ์ ๊ตฌ์ฑ ์์์์ ์ค๋ฅ๊ฐ ์บก์ฒ๋๋ฉด ํธ์ถ
-
- Vue 2 ์ฝ๋๋ฅผ Vue 3 Lifecycle Hooks ๋ก ์
๋ฐ์ดํธ๋ ํญ๋ชฉ
-
beforeCreate
-> use setup() -
created
-> use setup() -
beforeMount
-> onBeforeMount -
mounted
-> onMounted -
beforeUpdate
-> onBeforeUpdate -
updated
-> onUpdated -
beforeDestroy
-> onBeforeUnmount -
destroyed
-> onUnmounted -
errorCaptured
-> onErrorCaptured
-
-
props
,watch
๊ฐ ๋ง์์ง๋ฉด ์ ์ง๋ณด์๊ฐ ์ด๋ ค์ > ๋์ฉ๋ ๋ฐ์ดํฐ์ ์ฒ๋ฆฌ ๋ฐฉ๋ฒ๊ณผ ์ฑ๋ฅ ์ต์ ํ ๋ฐฉ๋ฒ (Vue.js Performance)
-
props
๊ฐ ๋ง๋ค๋ ๊ฒ์ ์ด๋ฏธ ๋ถ๋ชจ ์ปดํฌ๋ํธ(Parent Component)์์ ๋ง์ ์์ฑ์ ์ ๋ฌํ๊ณ ์๋ค๋ ๊ฒ -
props
๋ ํด๋น ์ปดํฌ๋ํธ์์ ์ง์ ์ ์ผ๋ก ๋ณ๊ฒฝ ๋ถ๊ฐ๋ฅ > ์ด๋ฏธ ๋์ด์จprops
๋ฅผ ๋ณ๊ฒฝํ๋ ค๋ฉด ๋ฐ์ธ๋ฉ ๋์ด์๋props
๋ฅผ data ์ ์ฌ ๋ฐ์ธ๋ฉํด์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์-
watch
์ ๊ฐ์ ๊ฐ์์์ ์์ ์ปดํฌ๋ํธ๋ก ์ด๋ฒคํธ๋ฅผ ์ ๋ฌํ๋$emit
์ด ๋ง์์ง
-
-
watch
๊ฐ ๋ง๋ค๋ ๊ฒ์ ์ด๋ฏธ ํด๋น ์ปดํฌ๋ํธ์์ ๋ฐ๊ฐ์ ์ ์ผ๋ก ๋ฐ์์ ์ธ ๋ชจ๋ธ์ด ํ์ํ๋ค๋ ๊ฒ -
watch
๊ฐ ๋ง์์ง๊ฒ ๋๋ฉด ํด๋น ์ปดํฌ๋ํธ๋ฅผ ๋ค๋ฅธ ๊ณณ์ ๋ฐ์ธ๋ฉํ์์ ๋ ์๋์น ์์ ๋์์ ์ผ๊ธฐํ ์ ์์ - ํนํ๋ Vue.js ์ ๋ฐ์์ ๋ชจ๋ธ์ Application ์ ์ฑ๋ฅ์ ์ง์ ์ ์ธ ์ฐ๊ด >
watch
์ต์ํ
- ์ ํจํ์ง ์์ ๊ฐ์ Submit ํ๋ฉด ์ ์ถ ๋ฒํผ์ด ๋นํ์ฑํ ๋๋ ๋ฑ, ์๋ชป๋ ํํ์ Request๋ฅผ ๋ณด๋ด์ง ์๊ฒ ์ฐจ๋จํด์ผ ํจ
- value ๊ฐ์ด ๋ณ๊ฒฝ๋๋ฉด(@change) ์ฒ๋ฆฌํ๋ ๋ฐฉ์์ด ์กด์ฌํ๋, ์ฌ์ฉ์๊ฐ focus out ํด์ผ๋ง change ์ํ๊ฐ ์ธ์๋๋ค๋ ๋ฌธ์ ์ ๆ
- ์ ํจ์ฑ์ ์ฒดํฌ๋ฅผ ๋ชจ๋ ํต๊ณผํด์ผ Submit :
v-form
์ref="form"
๊ธฐ์ฌ -
:rules
: ๊ฐ์ ธ์ฌ ๊ท์น๋ช ์ ์ ๋ ฅ
<v-form ref="form" @submit.prevent="login">
<v-text-field
:rules="emailRule"
/>
</v-form>
<script lang="ts">
data: () => ({
email: "",
password: "",
passwordShow: false,
autoLoginCheckBox: false,
emailRule: [
(v) => !!v || "์ด๋ฉ์ผ์ ์
๋ ฅํด์ฃผ์ธ์.",
(v) => {
const replaceV = v.replace(/(\s*)/g, "");
const pattern =
/^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$/;
return pattern.test(replaceV) || "์ด๋ฉ์ผ ํ์์ผ๋ก ์
๋ ฅํด์ฃผ์ธ์";
},
],
passwordRule: [
(v) => !!v || "๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.",
(v) => {
const replaceV = v.replace(/(\s*)/g, "");
return replaceV.length >= 8 || "8์๋ฆฌ ์ด์ ์
๋ ฅํด์ฃผ์ธ์.";
},
],
});
</script>
- Submit ์์๋
this.$refs.form.validate()
๋ก ์ ํจ์ฑ ์ฒดํฌ ๊ฒฐ๊ณผ ํ์ธ ๊ฐ๋ฅ
<script>
methods:{
async login(){
const validate = this.$refs.form.validate()
if (validate){
const email = this.email.replace(/(\s*)/g, '')
const password = this.password.replace(/(\s*)/g, '')
await this.$store.dispatch('LOGIN', { email, password, saveLogin:this.autoLoginCheckBox })
}
}
}
</script>
- q-form ์ ref ๊ฐ ์ง์
-
:rules="[user_pw_rules]"
: script ์์ ์ฒ๋ฆฌํ ํจ์ user_pw_rules ๊ธฐ์ฌ
-
<q-form ref="loginForm" class="q-gutter-md">
<q-input square filled clearable v-model="user_id" :rules="[user_id_rules]" type="text" label="ID" />
<q-input square filled clearable v-model="user_pw" :rules="[user_pw_rules]" type="password" label="password" />
</q-form>
- ์ ํจ์ฑ ์ฒดํฌ์ ์๋ฐ๋๋ ๊ฒฝ์ฐ, ๋นจ๊ฐ ํ ๋๋ฆฌ๊ฐ ์๊ธฐ๋ฉด์ ํ๋จ์ ์๋ฌ ๋ฌธ๊ตฌ๊ฐ ์ถ๋ ฅ๋๋ ๊ฒ์ด ๋ํดํธ ๋์
- boolean ํจ์/๋ณ์๋ค์ ๋ฃ์ ์ ์์ผ๋, async-await(Promise)๋ ๋ฃ์ ์ ์์
- ์๋์ ๊ฐ์ด rules ์ ๋ฐ๋ก ์ ํจ์ฑ ์ฒดํฌ ๋ก์ง์ ์ถ๊ฐํ ์ ์์
:rules="[val => val.length <= item.maxLength || `${item.maxLength}์๋ฅผ ์ด๊ณผํ์ต๋๋ค.`]"
:rules="[val => !getNotNullYn(val, item) || 'ํ์๋ก ์
๋ ฅ๋์ด์ผ ํฉ๋๋ค.'
, val => { let textLength = getTextLength(val);
return textLength <= item.maxLength || `${item.maxLength}์๋ฅผ ์ด๊ณผํ์ต๋๋ค.`} ]"
<q-form ref="updateForm">
<q-input
v-if="item.type === 'text'"
type="text"
:rules="[val => !getNotNullYn(val, item) || 'ํ์๋ก ์
๋ ฅ๋์ด์ผ ํฉ๋๋ค.'
, val => { let textLength = getTextLength(val);
return textLength <= item.maxLength || `${item.maxLength}์๋ฅผ ์ด๊ณผํ์ต๋๋ค.`} ]"
v-model="item.data"
/>
<q-input
v-if="item.type === 'number'"
type="number"
:rules="item.maxLength && [val => val.length <= item.maxLength || `${item.maxLength}์๋ฅผ ์ด๊ณผํ์ต๋๋ค.`]"
v-model="item.data"
/>
<q-btn label="์ถ๊ฐ" @click="updateInfo('1', clickedRow)" />
</q-form>
<script setup>
const updateForm = ref(null); // ์
๋ ฅ/์์ ํผ
const updateInfo = async (type, updatedRow) => {
const valid = await updateForm.value.validate(); // ์ ํจ์ฑ ๊ฒ์ฌ ๊ฒฐ๊ณผ๋ฅผ ๋ด์
if (!valid) {
$q.notify({ color: 'negative', message: '์ ํจํ ๊ฐ์ด ์๋๋๋ค.' });
return;
}
const bmigHeaders = new Headers();
bmigHeaders.append('Content-Type', 'application/x-www-form-urlencoded');
// ์ค๋ต (Submit ํ๋ ๊ณผ์ )
};
</script>
์ด๋ฒคํธ๋ช | ์ค๋ช |
---|---|
click | ๋ง์ฐ์ค๋ฅผ ํด๋ฆญํ์ ๋ ์คํํจ |
dblclick | ๋ง์ฐ์ค๋ฅผ ๋๋ธ ํด๋ฆญํ์ ๋ ์คํํจ |
mouseover | ๋ง์ฐ์ค์ ํฌ์ธํธ๊ฐ ์์ ์๋ก ์ฌ๋ผ์์ ๋ ์คํํจ |
mouseout | ๋ง์ฐ์ค์ ํฌ์ธํธ๊ฐ ์์ ๋ฐ์ผ๋ก ๋ฒ์ด๋ฌ์ ๋ ์คํํจ |
mousemove | ๋ง์ฐ์ค์ ํฌ์ธํธ๊ฐ ์ด๋ํ์ ๋ ์คํํจ |
mousedown | ๋ง์ฐ์ค์ ๋ฒํผ์ ๋๋ ์ ๋ ์คํํจ |
mouseup | ๋ง์ฐ์ค์ ๋ฒํผ์ ๋์์ ๋ ์คํํจ |
keydown | ํค๋ณด๋์ ํค๋ฅผ ๋๋ ์ ๋ ์คํํจ |
keyup | ํค๋ณด๋์ ํค๋ฅผ ๋์์ ๋ ์คํํจ |
keypress | ํค๋ณด๋์ ํค๋ฅผ ๋๋ ๋ค๊ฐ ๋์์ ๋ ์คํํจ |
change | ์์๊ฐ ๋ณ๊ฒฝ๋ ๋ ์คํํจ |
submit | Form ์ด ์ ์ถ๋ ๋ ์คํํจ |
reset | Form ์ด ์ฌ์ค์ ๋ ๋ ์คํํจ |
select | select ์ ๊ฐ์ด ์ ํ๋์์ ๋ ์คํํจ |
focus | ํ๊ทธ์ ํฌ์ปค์ค๊ฐ ์์ ๋ ์คํํจ |
blur | ํ๊ทธ์ ํฌ์ปค์ค๋ฅผ ์์์ ๋ ์คํํจ |
- Event ์ฌ๋ฌ ๊ฐ ์ฌ์ฉ ์ ๋๊ดํธ ์์์ ์ฝค๋ง๋ก ๊ตฌ๋ถ
<template>
<div>
<button @click="[method1(), method2()]">ํด๋ฆญ ๋ฒํผ</button>
</div>
</template>
- https://axios-http.com/kr/docs/intro
- node.js์ ๋ธ๋ผ์ฐ์ ๋ฅผ ์ํ Promise ๊ธฐ๋ฐ HTTP ํด๋ผ์ด์ธํธ
- ๋์ผํ ์ฝ๋๋ฒ ์ด์ค๋ก ๋ธ๋ผ์ฐ์ ์ node.js์์ ์คํํ ์ ์์
- ์๋ฒ ์ฌ์ด๋์์๋ ๋ค์ดํฐ๋ธ node.js์ http ๋ชจ๋์ ์ฌ์ฉ, ํด๋ผ์ด์ธํธ(๋ธ๋ผ์ฐ์ )์์๋ XMLHttpRequests๋ฅผ ์ฌ์ฉ
- ๋ธ๋ผ์ฐ์ ๋ฅผ ์ํด XMLHttpRequests ์์ฑ
- node.js๋ฅผ ์ํด http ์์ฒญ ์์ฑ
- Promise API๋ฅผ ์ง์
- ์์ฒญ ๋ฐ ์๋ต ์ธํฐ์ ํธ
- ์์ฒญ ๋ฐ ์๋ต ๋ฐ์ดํฐ ๋ณํ
- ์์ฒญ ์ทจ์
- JSON ๋ฐ์ดํฐ ์๋ ๋ณํ
- XSRF๋ฅผ ๋ง๊ธฐ์ํ ํด๋ผ์ด์ธํธ ์ฌ์ด๋ ์ง์
- Javascript >
findIndex()
,find()
(์ฐธ๊ณ ์๋ฃ ๋ฐ๋ก๊ฐ๊ธฐ) - ๊ฐ์ฒด์ ์์ฑ๊ฐ ๊ฐ์ ธ์ค๊ธฐ
- String ์ผ๋ก :
item['bmigEnginePkey']
item.bmigEnginePkey
- String ์ผ๋ก :
if (res.status === 200) {
res = await res.json();
console.log(res.rows);
console.log(res.rows[0]['bmigEnginePkey']);
console.log(res.rows.findIndex((item) => item['bmigEnginePkey'] === 73));
console.log(res.rows.findIndex((item) => item.bmigEnginePkey === 73));
}