April 01, 2020
순수 JavaScript나 jQuery로 DOM에 직접 접근할 수도 있지만, refs를 사용할 수도 있다.
컴포넌트가 mounted될 때, input에 focus를 줘보자.
아래와 같이 jQuery로 input에 focus를 줄 수 있다.
<input type="text" id="idInput" />mounted () {
$('#idInput').focus()
}아래와 같이 refs를 사용하여 input에 focus를 줄 수도 있다.
<input type="text" ref="idRef" />mounted () {
this.$refs.idRef.focus()
}