programing

VueJS2에서 이벤트 대상을 $emit 인수로 전달하려면 어떻게 해야 합니까?

itsource 2022. 8. 7. 17:06
반응형

VueJS2에서 이벤트 대상을 $emit 인수로 전달하려면 어떻게 해야 합니까?

이 VueJS 2 템플릿이 있습니다.

    var aThing = Vue.component('something',{
    template :` <button @click="$emit('custom-event','hello there')">Click me</button>`});

실제로 눌렀던 버튼을 넘길 수 있을까요?$emit예를 들어,click보통 통과하지만 이벤트와 같은 함수로 접근할 수 있는 경우

function(event){
  event.target; //I want this
}

여기 내 이슈의 jsfidle이 있다.

https://jsfiddle.net/wntzv4sk/2/

Vue는 다음 변수를 통해 템플릿에서 이벤트 개체를 사용할 수 있도록 합니다.$event여기에 기재되어 있습니다.

이 경우 다음과 같은 방법으로 이벤트의 타깃을 내보낼 수 있습니다.

$emit('custom-event', 'hello-there', $event.target)

언급URL : https://stackoverflow.com/questions/47875017/how-to-pass-the-event-target-as-emit-argument-in-vuejs2

반응형