button을 클릭 시 disable된 경우 클릭이 불가능 하게 만들고 싶다.
Menu 컴포넌트 사용
<template>
<menu
:List="List"
@handleClick="btnClick"
/ >
</template>
<script setup>
import { ref } from 'vue';
import menu from '@/components/menu.vue'
const List = ([
{
btnTxt : "선택안함",
},
{
disabled: true,
btnTxt : "버튼1"
},
{
btnTxt : "버튼2"
},
])
</script>
하위 컴포넌트 (MENU 컴포넌트)
<template>
<button
type="button"
:class="`menu__btn ${item.disabled ? 'menu__btn--disabled' : '' }`"
v-for="(item, index) in List"
:key="index"
@click=" item.disabled ? null : $emit('handleClick')""
>
{{ item.btnTxt }}
</button>
</template>
<script setup>
import { ref } from 'vue';
const props = defineProps({
List : {
type: Array,
default: [],
},
btnTxt : {
type: String,
default: '',
},
disabled : {
type: Boolean,
defualt: false,
},
});
</script>
item.disabled ? null : $emit('handleClick')을 줌으로서
item.disabled가 true인 경우에는 null값,
그 외에는 $emit('handleClick')으로 자식 → 부모 컴포넌트로 데이터를 전달주면 됩니다.
'비전공자 검은콩의 몸으로 부딪히는 실무' 카테고리의 다른 글
| [Vue3] Chart.js 툴팁 금지 (0) | 2023.08.09 |
|---|---|
| [Vue3] 원형차트에 그라데이션 넣기 (0) | 2023.08.09 |
| [Vue3] 클릭 시 데이터 가져오기, emit 사용법 (0) | 2023.08.09 |
| [Slick] 슬라이드 코드펜 autoplay (0) | 2023.08.07 |
| [css] input css 디자인 하기(input 디자인 코드펜) (0) | 2023.08.07 |