composition api 의 <script setup> 을 이용하여 다른 컴포넌트의 값을 가져오거나
다른 컴포넌트 함수를 호출하는 방법을 알아보도록 한다.
App.vue
<script setup> const dd = (log, head='') => { console.log('>>>'+head); console.log(log) }; import { ref, onMounted, onUnmounted, watch, reactive, defineExpose, defineProps, } from 'vue'; import send from '@/components/send.vue' const child = ref(null); const onCall = () => { dd(child.value.a, 'child.value.a') child.value.tt(); }; onMounted(()=>{ Worker.init(); onCall(); }) </script> <template> <div> <send ref="child"/> </div> </template>
send.vue (자식 컴포넌트)
<script setup> import { W1910A01 } from '@/store/W1910A01'; const a = '123'; const tt =_=>alert(123); defineExpose({ tt,a }); </script> <template> </template>
주의) defineExpose 없으면 작동하지 않습니다.
Call a function from another component using composition API
Below is a code for a header and a body (different components). How do you call the continue function of the component 2 and pass a parameter when you are inside component 1, using composition API ...
stackoverflow.com
defineExpose from component's <script setup> not working in vue 3
New to Vue in general and currently using 3.2.37, I possibly missunderstood the correct usage of composition api’s defineExpose directive as documented here: https://vuejs.org/api/sfc-script-setup....
stackoverflow.com
'프로그래밍 > Js' 카테고리의 다른 글
[javascript] 변수에 변수값 넣고 싶을때 (동적변수, 가변변수) (0) | 2023.07.06 |
---|---|
js 배열의 index 값을 객체의 키로 변경하는 방법 [] -> {} (0) | 2023.06.20 |
변수로 클래스 인스턴스 생성할때 (0) | 2023.06.12 |
vue3 갑자기 Error: Cannot find module 'vue/compiler-sfc' 발생시 (0) | 2023.05.19 |
vue options API vuex Store modules 사용법 (0) | 2023.04.13 |