v-bind

  • HTML 태그의 속성을 셋팅할 때는 v-bion:속성명을 사용한다.
  • v-bind는 생략이 가능하다. (v-bind: => : )



link바인딩하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
 
    <div id="test1">
        <h3>{{str1}}</h3>
        <a v-bind:href='link'>link</a>
<a :href='link'>link</a><br>
    </div>
 
<script src="https://unpkg.com/vue"></script>
<script>
    new Vue({
        el : '#test1',
        data : {
            str1 : '문자열 입니다.',
            link : 'http://kr.vuejs.org'
        }
    })
</script>
</body>
</html>
cs




이미지 바인딩하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
 
    <div id="test1">
        <img :src="imageName" :width="imageWidth"><br>
    </div>
 
<script src="https://unpkg.com/vue"></script>
<script>
    new Vue({
        el : '#test1',
        data : {
            imageName : 'logo.png',
            imageWidth : '200'
        }
    })
</script>
</body>
</html>
cs





마우스를 이미지에 올리면 이미지사이즈가 400으로 변경되고 마우스가 해제되면 200으로 되는 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
 
    <div id="test1">
        <img :src="imageName" :width="200"><br>
 
        <!-- v-on:mouseenter 마우스로 클릭했을때 -->
        <!-- v-on:mouseleave 마우스로 클릭했을때 -->
        <img :src="imageName" :width="imageWidth" v-on:mouseenter='setImageWidth' v-on:mouseleave='resetImageWidth
        '>
    </div>
 
<script src="https://unpkg.com/vue"></script>
<script>
    new Vue({
        el : '#test1',
        data : {
            imageName : 'logo.png',
            imageWidth : '200'
        },
        methods : {
            setImageWidth : function(){
                this.imageWidth = '400'
            },
            resetImageWidth : function(){
                this.imageWidth = '200'
            }
        }
    })
</script>
</body>
</html>
cs


'Vue' 카테고리의 다른 글

props, event emit 컴포넌트의 유효범위  (0) 2019.07.31
css 클래스 바인딩  (0) 2019.07.31
set, get  (0) 2019.07.31
Watch 와 Computed  (0) 2019.07.31
computed  (0) 2019.07.31

+ Recent posts