🙄 Virtual DOM
🙄 양방향 바인딩
기초 코드
const {createApp} = Vue: Vue 라이브러리를 creatApp에 저장
data(){return{}}: 담을 data를 정의
.mount(): 연결할 id명 또는 class명 기입
<head>
<script src="https://unpkg.com/vue@3"></script>
</head>
<body>
<div id="app">{{ message }}</div>
<button @click="sum++">숫자세기 : {{ sum }}</button> <!--script에서 sum 초기값을 0으로 정의 후 클릭 때마다 ++ 적용-->
<script>
const {createApp} = Vue
createApp({
data() { //담을 data
return {
message: '안녕 Vue',
sum: 0
}
}
}).mount('#app')
</script>
</body>
methods
click 등 이벤트 발생 시 실행할 함수 정의
<!--html 부분-->
<button @click="change">변경</button>
<!--script 부분-->
methods: {
change: function(){ // 클릭 시 change라는 함수 실행
this.message = "바이 뷰!"
}
}
mounted(){}
Vue의 기본 함수, 초기 화면이 렌더링 되고 실행되는 함수
methods : { ~~ },
mounted(){
console.log(`숫자 초기값은 ${this.count} 입니다`)
}
@click.prevent
e.preventDefault()가 작동함
stopPropagation()와 동일. 이벤트 전파를 차단함
<a href="http://vuejs.org" @click.prevent="notify">e.preventDefault()가 작동하는 링크</a>
HTML의 vue 태그
@click: click 시 실행
:title: 마우스를 갖다대면 풍선 도움말이 뜸
:class=”{}”: 클래스명을 정의 :class="{red:true}" == .red
:style="{}”: style 속성값을 정의 :style="{border}" == style='border:정의한값’
v-if: ex)v-if="show && list.length” v-else-if, v-else
v-for: vue의 반복문 ex)v-for="item of list”
v-model: input값을 받아오는 vue 축약어
ex) @input="데이터명 = $event.target.value”