[vue.js] event

gga·2022년 5월 11일
0

Vue

목록 보기
2/3

event

custom event

event name

케밥-케이스 사용

v-on 이벤트 이름은 소문자로 자동 변환되기 때문에 반드시 케밥 케이스를 사용해야한다.

this.$emit('my-event')
<my-component @my-event="doSomethig"></my-compoenent>

emitted 이벤트 이름과 100% 똑같아야 한다.

이벤트 이름은 자동 변환을 제공하지 않는다. 그래서 emitted evnet nameevent name은 완벽히 동일해야 한다.

emit

사전적 정의

emit: (빛·열·가스·소리 등을) 내다[내뿜다]

사용법

매개변수

<button @click="$emit('enlarge-text', 0.1)">Enlarge text</button>
<blog-post @enlarge-text="postFontSize+= $event"></blog-post>

method

출처

Vue.js v2.x 공식문서

https://v2.vuejs.org/v2/guide/components-custom-events.html

https://v2.vuejs.org/v2/guide/components.html#Emitting-a-Value-With-an-Event

0개의 댓글