props
props
props
๋ ๋ถ๋ชจcomponent๊ฐ ์์component์๊ฒ data๋ฅผ ์ ๋ฌํ๋ ๊ฒ
์์ component
์์component๋ฅผ AppCard.vue
๋ก ์ ์
html
<template>
<div>
<p>
{{ $props }} <!--$๋ก๋ ๋งํฌ์
์ผ๋ก ํํ๊ฐ๋ฅ-->
</p>
<span>{{ type == 'news' ? '๋ด์ค' : '๊ณต์ง์ฌํญ'}}</span> <!--computed๋ก ํํ๊ฐ๋ฅ-->
<h2>
{{ title }}
</h2>
<p>
{{ contents }}
</p>
<p :class="isLikeClass"> <!--computed ์ฌ์ฉ-->
์ข์์
</p>
</div>
</template>
js
<script setup>
const props = defineProps({
type: {
type: String,
default: 'news',
validator: value => {
return 'undefined' || ['news', 'notice'].includes[value];
}, //์ ์ธ์ด ์๋์ด๋ ๊ฐ๋ฅํ์ง๋ง ์ ์ธํ ๊ฒฝ์ฐ news๋ notice๋ง ๊ฐ๋ฅํ๋ค
},
title: String,
contents: String,
isLike: {
type: Boolean
}
});
const isLikeClass = computed(() => props.isLike ? 'btn-good': 'btn-bad');
</script>
css
div{
margin-bottom: 40px;
border: 10px solid;
}
.btn-good{
background: red;
}
.btn-bad{
background: green;
}
๋ถ๋ชจ component
๋ถ๋ชจcomponent๋ฅผ TheView.vue
๋ก ์ ์
html
<!-- ์ง์ ๊ฐ๋ฃ๊ธฐ -->
<AppCard title="์ ๋ชฉ1" contents="๋ด์ฉ1"></AppCard>
<!-- ๊ฐ์ฒด์ ํ๋๊ฐ ์ฌ์ฉ -->
<AppCard :title="post1.title" :contents="post1.contents" :isLike="post1.isLike"></AppCard>
<!-- ๊ฐ์ฒด ์ฌ์ฉ -->
<AppCard v-bind="post3"></AppCard>
<!-- ๊ฐ์ฒด+๋ฐ๋ณต๋ฌธ -->
<div v-for = "post in posts" :key="post.id">
<AppCard
:title="post.title"
:contents="post.contents"
:type="post.type"
:isLike="post.isLike"
></AppCard>
</div>
js
const post1 = {
title: '์ ๋ชฉ2',
contents: '๋ด์ฉ2',
isLike: true,
}
const post3 = {
title: '์ ๋ชฉ3',
contents: '๋ด์ฉ3',
isLike: true,
type: "notype",
}
const posts = reactive([
{title:'์ ๋ชฉ4', contents:'๋ด์ฉ4', isLike:false, type:'notice'},
{title:'์ ๋ชฉ5', contents:'๋ด์ฉ5', isLike:false, type:'notice'},
]);
์ฐธ๊ณ ์๋ฃ: Vue3 ์๋ฒฝ ๋ง์คํฐ: ๊ธฐ์ด๋ถํฐ ์ค์ ๊น์ง - โ๊ธฐ๋ณธํธโ
์์ค์ฝ๋ ๋ฐ๋กํ์ธํ๊ธฐ
Javascript
๐ pinia๊ธฐ๋ณธ
2023.05.05
๐ Route
2023.04.01
๐ Template ref
2023.03.26
๐ provide์ inject
2023.03.25
๐ slots
2023.03.24
๐ nonProps
2023.03.23
๐ props
2023.03.20
๐ watch
2023.03.19
๐ ์๋ฐฉํฅ ๋ฐ์ธ๋ฉ
2023.03.18
๐ event Parameter
2023.03.17
๐ Scope์ Closure
2023.03.17
๐ classStyleBinding
2023.03.16
๐ computed
2023.03.15
๐ Ref์ Reactive
2023.03.14
๐ Json
2021.04.16
๐ Javascript ๋ฐฐ์ด
2021.04.15
๐ Javascript ๊ฐ์ฒด
2021.04.14
๐ Javascript ํด๋์ค
2021.04.13
๐ Javascript ํจ์
2021.04.12
๐ Javascript ๋ณ์์ฌํ
2021.04.11
๐ Javascript ๋ณ์
2021.04.10
Frontend
๐ pinia๊ธฐ๋ณธ
2023.05.05
๐ Route
2023.04.01
๐ Template ref
2023.03.26
๐ provide์ inject
2023.03.25
๐ slots
2023.03.24
๐ nonProps
2023.03.23
๐ props
2023.03.20
๐ watch
2023.03.19
๐ ์๋ฐฉํฅ ๋ฐ์ธ๋ฉ
2023.03.18
๐ event Parameter
2023.03.17
๐ Scope์ Closure
2023.03.17
๐ classStyleBinding
2023.03.16
๐ computed
2023.03.15
๐ Ref์ Reactive
2023.03.14
๐ Json
2021.04.16
๐ Javascript ๋ฐฐ์ด
2021.04.15
๐ Javascript ๊ฐ์ฒด
2021.04.14
๐ Javascript ํด๋์ค
2021.04.13
๐ Javascript ํจ์
2021.04.12
๐ Javascript ๋ณ์์ฌํ
2021.04.11
๐ Javascript ๋ณ์
2021.04.10
๐ CSS Centering
2021.04.09
๐ CSS flexbox
2021.04.08
๐ CSS ๋ณ์
2021.04.07
๐ CSS Size
2021.04.06
๐ CSS layout
2021.04.05
๐ CSS ๊ธฐ๋ณธ
2021.04.04
๐ HTML5 Data ์์ฑ
2021.04.03
๐ HTML์ ๋ค์ํ ํ๊ทธ
2021.04.02
๐ Visual studio code์ ์ ์ฉํ ํด
2021.04.01
๐ HTML ๊ธฐ์ด
2021.04.01
Vue
๐ pinia๊ธฐ๋ณธ
2023.05.05
๐ Route
2023.04.01
๐ Template ref
2023.03.26
๐ provide์ inject
2023.03.25
๐ slots
2023.03.24
๐ nonProps
2023.03.23
๐ props
2023.03.20
๐ watch
2023.03.19
๐ ์๋ฐฉํฅ ๋ฐ์ธ๋ฉ
2023.03.18
๐ event Parameter
2023.03.17
๐ classStyleBinding
2023.03.16
๐ computed
2023.03.15
๐ Ref์ Reactive
2023.03.14
๋๊ธ ์ฐ๊ธฐ