디렉티브 : v-bind
v-bind
속성을 디렉티브라고 한다.
Vue에서 제공하는 특수 속성임을 나타내기 위해 v-
접두사가 붙어있있다.
이는 렌더링된 DOM에 특수한 반응형 동작을 한다.
<div id="app2">
<span v-bind:title="title">
내 위에 잠시 마우스를 올리면 동적으로 바인딩 된 title을 볼 수 있습니다!
</span>
</div>
var app2 = new Vue({
el: '#app-2',
data: {
message: '이 페이지는 ' + new Date() + ' 에 로드 되었습니다'
}
})
DOM 구조에도 데이터를 바인딩할 수 있다.
Vue 엘리먼트가 Vue에 삽입/업데이트/제거될 때 자동으로 트랜지션 효과를 적용할 수 있다.
조건문 : v-if
<div id="app3">
<p v-if="seenStatus">보이기!</p>
</div>
const app3 = new Vue({
el: "#app3",
data: {
seenStatus: true,
},
});
반복문 : v-for
<div id="app4">
<ol>
<li v-for="todo in todos">{{todo.text}}</li>
</ol>
</div>
const app4 = new Vue({
el: "#app4",
data: {
todos: [{ text: "1" }, { text: "2" }, { text: "3" }],
},
});
이벤트 리스너 추가 : v-on
<div id="app5">
<p>{{message}}</p>
<button v-on:click="reverseMessage">메시지 뒤집기</button>
</div>
const app5 = new Vue({
el: "#app5",
data: {
message: "안녕 잘가",
},
methods: {
reverseMessage: function () {
this.message = this.message.split("").reverse().join("");
},
},
});
입력과 앱 상태의 양방향 바인딩 : v-model
<div id="app6">
<p>{{ message }}</p>
<input v-model="message" />
</div>
const app6 = new Vue({
el: "#app6",
data: {
message: "입력하세용",
},
});
Vue에서 컴포넌트는 미리 정의된 옵션을 가진 Vue 인스턴스이다.
Vue에서 컴포넌트 등록하는 방법
props로 todo를 등록한다. props는 부모가 자식 컴포넌트에게 데이터를 넘겨줄 수 있게 된다. todo를 컴포넌트 v-bind
로 연결한다.
<div id="app-7">
<ol>
<!--
Now we provide each todo-item with the todo object
it's representing, so that its content can be dynamic.
We also need to provide each component with a "key",
which will be explained later.
-->
<todo-item
v-for="item in groceryList"
v-bind:todo="item"
v-bind:key="item.id"
></todo-item>
</ol>
</div>
Vue.component('todo-item', {
props: ['todo'],
template: '<li>{{ todo.text }}</li>'
})
var app7 = new Vue({
el: '#app-7',
data: {
groceryList: [
{ id: 0, text: 'Vegetables' },
{ id: 1, text: 'Cheese' },
{ id: 2, text: 'Whatever else humans are supposed to eat' }
]
}
})
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing