728x90
반응형
TAB 클릭시에 비동기로 데이터 호출 방법
<template>
<div>
<ul>
<li v-for="(tab, index) in tabs" :key="index" :class="{ 'on': activeTab === index }" @click="changeTab(index)">
{{ tab }}
</li>
</ul>
</div>
</template>
export default {
data(){
return {
tabs: ['TAB_1', 'TAB_2', 'TAB_3', 'TAB_4', 'TAB_5', 'TAB_6'],
activeTab: 0,
code: 'code_1'
},
methods: {
changeTab(index){
this.activeTab = index;
this.getTabData(this.code);
},
getTabData(cd) {
switch (this.activeTab) {
case 0:
this.getData(cd);
break;
case 1:
console.log(this.activeTab);
break;
case 2:
console.log(this.activeTab);
break;
case 3:
console.log(this.activeTab);
break;
case 4:
console.log(this.activeTab);
break;
case 5:
console.log(this.activeTab);
break;
default:
},
getData(){
axios.post().then(response => { console.log(response) });
}
}
}
swich로 각 탭에 대한 메소드 적용
728x90
반응형
'공부의 > vuejs' 카테고리의 다른 글
[vuejs] Dropzone vue3로 파일 드래그앱드롭 업로드 구현하기 (0) | 2023.04.17 |
---|---|
[vuejs] base64 첨부파일 새 탭으로 미리보기 기능 (0) | 2023.03.24 |
[vuejs] daterangepicker 새로고침 해야 나오는 현상, 페이지 이동시 작동 안됨 오류 (0) | 2023.03.22 |
[vuejs] json 객체로 테이블 동적 생성하기(체크박스 모두 선택 제어) (0) | 2023.03.21 |
[vue.js] 네이버 지도 api 사용하기 (아직 도메인이 없을때) (0) | 2023.02.21 |