Vue 3 + Typescript에서 방출 작업
                                            
                                                
                                                
                                                
                                                
                                                
                                                 4254 단어  vuejavascripttypescript
                    
<script setup>를 사용하여 emits Vue 3 + Composition API로 작업하는 방법을 보여드리겠습니다. 작업할 수 있는 방법이 거의 없습니다. 살펴보겠습니다!defineEmits() 매크로를 사용하여 다음과 같이 방출을 선언할 수 있습니다.
1 - 문자열 배열
<script setup>
const emit = defineEmits(['inFocus', 'submit'])
function buttonClick() {
  emit('submit')
}
</script>
2 - 개체 구문
<script setup>
const emit = defineEmits({
  submit(payload) {
    // return `true` or `false` to indicate
    // validation pass / fail
  }
})
</script>
3 - 런타임 또는 기본 유형 선언
<script setup lang="ts">
// runtime
const emit = defineEmits(['change', 'update'])
// type-based (TS)
const emit = defineEmits<{
  (e: 'change', id: number): void
  (e: 'update', value: string): void
}>()
</script>
그게 다야!
구성 요소 방출 선언에 대한 자세한 내용을 읽고 알아보려면 Vue 3 official documentation about emits을 방문하십시오.
안녕!
기사 참조:
https://vuejs.org/guide/components/events.html
https://vuejs.org/guide/typescript/composition-api.html#typing-component-emits
Reference
이 문제에 관하여(Vue 3 + Typescript에서 방출 작업), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/caio2k/working-with-emits-in-vue-3-typescript-2a1j텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)