728x90
[목표]
1. 부모의 컴포넌트를 자식컴포넌트에서 사용하는 slot에 대한 이해를 해보았다.
그런데 slot이 여러개라면 어떻게 해야될까?
힌트
- <template v:slot="이름1">
- <slot name="이름1">
바로 전 포스팅 소스와 동일한 소스는 올리지 않았음
[UserInfo.vue]
<template>
<base-card>
<template v-slot:header>
<h3>{{ fullName }}</h3>
<base-badge :type="role" :caption="role.toUpperCase()"></base-badge>
</template>
<template v-slot:default>
<p>{{ infoText }}</p>
</template>
</base-card>
</template>
<script>
export default {
props: ['fullName', 'infoText', 'role'],
};
</script>
<style scoped>
section {
margin: 2rem auto;
max-width: 30rem;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
padding: 1rem;
}
section div {
display: flex;
justify-content: space-between;
align-items: center;
}
</style>
[BaseCard.vue]
<template>
<div>
<header>
<slot name="header"></slot>
</header>
<slot></slot>
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
div{
margin: 2rem auto;
max-width: 30rem;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
padding: 1rem;
}
</style>
<template v-slot:default>는
slot에 name 설정 안해놓은 걸로 설정된다.
'데일리 공부 기록' 카테고리의 다른 글
hands on vue - slot에 데이터 넘겨주기 (0) | 2023.03.10 |
---|---|
hands on vue - slot에 대해 더 알아보자 (0) | 2023.03.10 |
hands on vue - slot의 이해 (연습문제) (0) | 2023.03.09 |
hands on vue - scoped 스타일 적용 (0) | 2023.03.09 |
hands on vue - component의 global, local 이해(연습예제 고민하고 풀기!) (0) | 2023.03.09 |