[Vue.js] Template refs
๐ ํ
ํ๋ฆฟ refs๋? Props์ Event๊ฐ ์กด์ฌํ์ง๋ง, ์์ ์์์ JavaScript๋ฅผ ์ด์ฉํด ์ง์ ์ ๊ทผํด์ผ ํ ๋๊ฐ ์๋๋ฐ, ์ด ๋ `ref` ์์ฑ์ ์ด์ฉํด ์ฐธ์กฐ(Reference) ID๋ฅผ ์์ ์ปดํฌ๋ํธ๋, HTML ์์์ ๋ถ์ฌํจ์ผ๋ก ์ง์ ์ ๊ทผํ๊ฒ ํด ์ฃผ๋ ๊ฒ์ด์์. ์์ ๊ฐ์ด ์ปดํฌ๋ํธ๊ฐ Mount ๋์์ ๋, ํ๋ก๊ทธ๋๋ฐ ์ ์ผ๋ก input์ focus๋ฅผ ํ๊ณ ์ ํ๋ ๊ฒฝ์ฐ ๋ฑ์ ์ ์ฉํ๊ฒ ์ฌ์ฉํ ์ ์๋ ๊ฒ์ด์์. const app = Vue.createApp({}) app.component('base-input', { template: ` `, methods: { focusInput() { this.$refs.input.focus() } }, mounted() { this.focusInput()..
2022.03.19