티스토리 뷰
부모 컴포넌트에 정의되어 있는 method를 자식 컴포넌트에서 사용하고 싶을 때.
props로 해당 method를 받아 사용한다.
*Parent 컴포넌트
<template>
<div>
<ChildComponent
:method-name-kebabCase="parentMethod"
></ChildComponent>
</div>
</template>
<script>
import ChildComponent from './ChildComponent.vue'
export default {
components: {
ChildComponent
},
methods: {
parentMethod(){
return "text"
}
}
}
</script>
*Child 컴포넌트
<template>
<div>
<button
:class="`button ${getParentMethod(parentMethod)}`"
>getParentMethod(parentMethod)</button>
</div>
</template>
<script>
export default {
props: {
getParentMethod: {
type: Function,
default: () => {}
}
}
}
</script>
'Javascript > Vue' 카테고리의 다른 글
| [Vue 3] Vue.js devtools - not detected (0) | 2021.11.12 |
|---|---|
| [Vue 3] Router 설정하기 (2) | 2021.11.01 |
| [Vue.js] axios__WEBPACK_IMPORTED_MODULE_2___default.a.get(...).then(...).error is not a function (0) | 2021.06.28 |
| [Vue.js] router - url에 삽입되는 해시(#) 제거하기 (0) | 2021.06.24 |
| [Vue.js] vue cli 4 - sass 셋팅하기 (0) | 2021.05.17 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 중첩라우트
- vue3
- VUE
- jest
- webpack
- node-sass
- V-Model
- restful api server
- vue cli 4
- vueRouter
- sass-loader
- fetch
- 퍼블리셔
- scss
- SASS
- 프론트엔드
- nodes.js
- WAI-ARIA
- computed
- json server
- axios
- 탭컴포넌트
- 동적slot
- 토이프로젝트
- Babel
- 러닝자바스크립트
- polyfill
- Vue.js
- semantic
- 리팩토링
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함
