๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • What would life be If we had no courage to attemp anything?
Development/Vue.js

Vue.js - Vue Instance

by DevIseo 2022. 5. 7.

๐Ÿ””Basic syntax of Vue.js

|Vue instance

  • ๋ชจ๋“  Vue ์•ฑ์€ Vue ํ•จ์ˆ˜๋กœ ์ƒˆ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ๋ถ€ํ„ฐ ์‹œ์ž‘
  • Vue ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•  ๋•Œ๋Š” Options ๊ฐ์ฒด๋ฅผ ์ „๋‹ฌํ•ด์•ผ ํ•จ
  • ์—ฌ๋Ÿฌ Options๋“ค์„ ์‚ฌ์šฉํ•˜์—ฌ ์›ํ•˜๋Š” ๋™์ž‘์„ ๊ตฌํ˜„
  • Vue Instance === Vue Component
const app  = new Vue({
})

 

 

|Options/DOM - ‘el’

  • Vue ์ธ์Šคํ„ด์Šค์— ์—ฐ๊ฒฐ(๋งˆ์šดํŠธ) ํ•  ๊ธฐ์กด DOM ์š”์†Œ๊ฐ€ ํ•„์š”
  • CSS ์„ ํƒ์ž ๋ฌธ์ž์—ด ํ˜น์€ HTML Element๋กœ ์ž‘์„ฑ
  • new๋ฅผ ์ด์šฉํ•œ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋•Œ๋งŒ ์‚ฌ์šฉ
const app  = new Vue({
	el: '#app'
})

 

 

|Options/DOM - ‘data’

  • Vue ์ธ์Šคํ„ด์Šค์˜ ๋ฐ์ดํ„ฐ ๊ฐ์ฒด
  • Vue ์ธ์Šคํ„ด์Šค์˜ ์ƒํƒœ ๋ฐ์ดํ„ฐ๋ฅผ ์ •์˜ํ•˜๋Š” ๊ณณ
  • Vue template์—์„œ interpolation์„ ํ†ตํ•ด ์ ‘๊ทผ ๊ฐ€๋Šฅ
  • v-bind, v-on๊ณผ ๊ฐ™์€ directive์—์„œ๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
  • Vue ๊ฐ์ฒด ๋‚ด ๋‹ค๋ฅธ ํ•จ์ˆ˜์—์„œ this ํ‚ค์›Œ๋“œ๋ฅผ ํ†ตํ•ด ์ ‘๊ทผ ๊ฐ€๋Šฅ
const app  = new Vue({
	el: '#app',
	data : {
		message: 'hello',
	}
})

 

 

|Options/DOM - ‘methods’

  • Vue ์ธ์Šคํ„ด์Šค์— ์ถ”๊ฐ€ํ•  ๋ฉ”์„œ๋“œ
  • Vue template์—์„œ interpolation์„ ํ†ตํ•ด ์ ‘๊ทผ ๊ฐ€๋Šฅ
  • v-on๊ณผ ๊ฐ™์€ directive์—์„œ๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
  • Vue ๊ฐ์ฒด ๋‚ด ๋‹ค๋ฅธ ํ•จ์ˆ˜์—์„œ this ํ‚ค์›Œ๋“œ๋ฅผ ํ†ตํ•ด ์ ‘๊ทผ ๊ฐ€๋Šฅ
  • ์ฃผ์˜
    • ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ๋ฉ”์„œ๋“œ๋ฅผ ์ •์˜ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ ๋จ
    • ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๊ฐ€ ๋ถ€๋ชจ ์ปจํ…์ŠคํŠธ๋ฅผ ๋ฐ”์ธ๋”ฉํ•˜๊ธฐ ๋•Œ๋ฌธ์—, this๋Š” Vue ์ธ์Šคํ„ด์Šค๊ฐ€ ์•„๋‹˜.
const app  = new Vue({
	el: '#app',
	data : {
		message: 'hello',
	},
	methods : {
		gretting: function(){
			console.log('hello')
		}
	}
})

 

 

|this keyword in vue.js

  • Vue ํ•จ์ˆ˜ ๊ฐ์ฒด ๋‚ด์—์„œ vue ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€๋ฆฌํ‚ด
  • ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ ๋˜๋Š” ๊ฒฝ์šฐ
    • data
    • method ์ •์˜

'Development > Vue.js' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Vue.js - Vue CLI  (0) 2022.05.09
Vue.js - SFC(Single File Component)  (0) 2022.05.09
Vue.js - Lifecycle Hooks  (0) 2022.05.07
Vue.js - Template Syntax  (0) 2022.05.07
Vue.js - SPA, CSR,SSR,SEO,Vue.js์˜ ๊ฐœ๋…๊ณผ ์—ญํ• , MVVM  (0) 2022.05.07

๋Œ“๊ธ€