-
코딩 자율학습단(Vue.js 프런트엔드 개발 입문) 7일차정보교육/프런트엔드 2024. 6. 25. 09:29
5장 컴포넌트 다루기
5.5 컴포넌트의 데이터 효율적으로 다루기
컴포넌트의 데이터 공유하기(provide, inject)
// App.vue <script> import FirstChild from './components/FirstChild.vue'; export default { components: { FirstChild, }, provide() { return { message: this.message, }; }, data() { return { message: 'Hello, Vue.Js', }; }, } </script> <template> <FirstChild /> </template>
// FirstChild.vue <script> export default { inject: ['message'], } </script> <template> <h1>컴포넌트</h1> <p>내가 만든 첫 번째 컴포넌트</p> <h1> {{ message }}</h1> </template> <style> h1 { color: blue; } p { color: green; } </style>
컴포넌트의 데이터 참조하기($refs, $parent)
5.6 컴포넌트 슬롯 사용하기
이름이 없는 슬롯// CustomButton.vue <template> <button class="btn"> <slot></slot> </button> </template>
//App.vue <template> <CustomButton>더블클릭</CustomButton> </template>
이름이 있는 슬롯
// 형식 <template> <slot name="값"></slot> <slot name="header"></slot> <slot name="main"></slot> </template>
슬롯에 기본값 적용하기
<template> <button class="btn"> <slot>제출</slot> </button> </template>
'정보교육 > 프런트엔드' 카테고리의 다른 글
코딩 자율학습단(Vue.js 프런트엔드 개발 입문) 9일차 (0) 2024.06.28 코딩 자율학습단(Vue.js 프런트엔드 개발 입문) 8일차 (0) 2024.06.27 코딩 자율학습단(Vue.js 프런트엔드 개발 입문) 6일차 (0) 2024.06.24 vue.js 프로젝트: 일정 관리가 포함된 홈페이지 만들기 (0) 2024.06.23 코딩 자율학습단(Vue.js 프런트엔드 개발 입문) 5일차 (0) 2024.06.22