클릭 이벤트
<button @click="increaseCounter">Add 1</button>
change 이벤트
<select
name=""
id=""
v-on:change="changeCity($event)"
v-model="selectedCity"
>
<template>
<div>
<select
name=""
id=""
v-on:change="changeCity($event)"
v-model="selectedCity"
>
<option value="">===도시선택===</option>
<option
:value="city.cityCode"
:key="city.cityCode"
v-for="city in cityList"
>
{{ city.title }}
</option>
</select>
<select name="" id="">
<option
:value="dong.dongCode"
:key="dong.dongCode"
v-for="dong in selectedDongList"
>
{{ dong.dongTitle }}
</option>
</select>
<select name="" id="">
<option
:value="dong.dongCode"
:key="dong.dongCode"
v-for="dong in dongList.filter(
(dong) => dong.cityCode === this.selectedCity
)"
>
{{ dong.dongTitle }}
</option>
</select>
</div>
</template>
<script>
export default {
components: {},
data() {
return {
selectedCity: '',
cityList: [
{ cityCode: '02', title: '서울' },
{ cityCode: '051', title: '부산' },
{ cityCode: '064', title: '제주' }
],
dongList: [
{ cityCode: '02', dongCode: '1', dongTitle: '서울 1동' },
{ cityCode: '02', dongCode: '2', dongTitle: '서울 2동' },
{ cityCode: '02', dongCode: '3', dongTitle: '서울 3동' },
{ cityCode: '02', dongCode: '4', dongTitle: '서울 4동' },
{ cityCode: '051', dongCode: '1', dongTitle: '부산 1동' },
{ cityCode: '051', dongCode: '2', dongTitle: '부산 2동' },
{ cityCode: '051', dongCode: '3', dongTitle: '부산 3동' },
{ cityCode: '064', dongCode: '1', dongTitle: '제주 1동' },
{ cityCode: '064', dongCode: '2', dongTitle: '제주 2동' }
],
selectedDongList: []
}
},
created() {},
mounted() {},
unmounted() {},
methods: {
changeCity(event) {
console.log(event.target.tagName)
this.selectedDongList = this.dongList.filter(
(dong) => dong.cityCode === this.selectedCity
)
}
}
}
</script>
keyup (enter) 이벤트
<template>
<div>
<input
type="search"
name=""
id=""
@keyup="checkEnter($event)"
v-model="searchText"
/>
<input
type="search"
name=""
id=""
@keyup.enter="doSearch"
v-model="searchText"
/>
<button @click="doSearch">조회</button>
</div>
</template>
<script>
// .enter
// .tab
// .delete
// .esc
// .space
// .up
// .down
// .left
// .right
// .stop - event.stopPropagation()
// .prevent - event.preventDefault()
export default {
components: {},
data() {
return {
searchText: ''
}
},
created() {},
mounted() {},
unmounted() {},
methods: {
doSearch() {
console.log(this.searchText)
},
checkEnter(event) {
if (event.keyCode === 13) {
this.doSearch()
}
}
}
}
</script>
'Vue > Vue.js' 카테고리의 다른 글
1-7. computed와 watch (0) | 2024.09.10 |
---|---|
1-6. 렌더링 조건 (v-if, v-show) (0) | 2024.09.10 |
1-4. 데이터 바인딩 (0) | 2024.09.09 |
1-3. 라우터 (0) | 2024.09.09 |
1-2. 설치, 프로젝트 생성 및 구조 이해하기 (0) | 2024.09.09 |
댓글