반응형
Vue 2 - 클릭 이벤트 또는 입력 이벤트에서 실행되었을 때 $emit에서 다른 동작
아래 (여기에 fiddle)에서는 아래 클릭 이벤트에서 발생하는 $emit이 예상대로 작동합니다.입력이벤트에 의해 기동된 $emit은 같은 방법으로 배선되어 있습니다만, 부모에게는 $emit가 수신되지 않습니다.
<div id="app">
{{ message }}
<child-comp
:prop="property"
@emitted="receiveEmit"
@emittedFromInput="receiveEmitFromInput"
></child-comp>
{{ otherMessage }}
</div>
Vue.component('child-comp', {
template: '<div><button @click="sendEmit">emit</button><input type="text" @input="onInput"><p v-if="inputEventFired">The input event fired</p></div>',
data: function() {
return {
inputEventFired: false
};
},
methods: {
onInput: function(e) {
this.inputEventFired = true;
this.$emit('emittedFromInput', 'never see this');
},
sendEmit: function() {
this.$emit('emitted', 'can change from click event that emits');
}
}
});
new Vue({
el: '#app',
data: function() {
return {
message: 'allo',
otherMessage: 'cannot change this from input event that emits'
};
},
methods: {
receiveEmit: function(val) {
this.message = val;
},
receiveEmitFromInput: function(val) {
alert('i do not happen')
this.message = val;
}
}
});
위의 내용을 읽기 쉽게 하기 위해 자 컴포넌트의 템플릿은 다음과 같습니다.
<div>
<button @click="sendEmit">emit</button>
<input type="text" @input="onInput">
<p v-if="inputEventFired">The input event fired</p>
</div>
SO가 아닌 다른 사람이 도와줬는데, 그 정보를 여기에 올릴게요.여기서의 문제는, 이벤트도 이미터도 아니고, 오히려 html의 대소문자를 구별하지 않는 것입니다.@some Camel Cased Event는 실제로 @some Camel Cased Event. working fiel로서 javascript에 전달되는 것 같습니다.
this.$emit('emitted-from-input', 'never see this');
<child-comp
@emitted="receiveEmit"
@emitted-from-input="receiveEmitFromInput">
</child-comp>
언급URL : https://stackoverflow.com/questions/42438249/vue-2-different-behavior-on-emit-when-fired-from-click-or-input-event
반응형
'programing' 카테고리의 다른 글
C에서의 비트필드 조작 (0) | 2022.08.17 |
---|---|
클래스 Java Launch Helper는 2개의 장소에서 구현됩니다. (0) | 2022.08.17 |
vuex 로그에서 다음 상태와 이전 상태를 숨기는 방법 (0) | 2022.08.17 |
vuex에 저장된 json 데이터 추가 및 읽기 (0) | 2022.08.17 |
캐시가 없는 VueJs 계산 속성 (0) | 2022.08.17 |