티스토리 뷰

Front-end

[VueJS] attribute binding

코헴 2019. 5. 13. 13:31

[VueJS] attribute binding

String이 결합된 attribute binding

스트링과 결합된 어트리뷰트 바인딩은 다음과 같은 방식으로 할 수 있습니다.

<div id="app">
  <img :id="`thumbnail_${id}`" :src="image" />
</div>

<script>
  let app = new Vue({
    el: '#app',
    data() {
      return {
        id: 1,
        image: "https://naver.com"
      }
    }
  })
</script>

style attribute binding

style 속성또한 다음과 같은 방식으로 바인딩이 가능합니다.

<div id="app">
  <div :style="style">
    test
  </div>
</div>
<script>
  let app = new Vue({
    el: '#app',
    data() {
      return {
        style: 'background : white'
      }
    }
  })
</script>

Json 형태 & 다중 속성 삽입

배열 형태로 다양한 어트리뷰트 속성값을 지정할 수 있습니다.

<div id="app">
  <div :style="[style, fontStyle]">
    test
  </div>
</div>
<script>
  let app = new Vue({
    el: '#app',
    data() {
      return {
        id: 1,
        style: {
          background: 'red',
          fontSize: '10px',
          fontFamily: 'dotum'
        },
        fontStyle: {
            fontSize: '10px',
            fontFamily: 'dotum'
        }
      }
    }
  })
</script>

'Front-end' 카테고리의 다른 글

[VueJS] component  (0) 2019.05.13
[VueJS] method & event handling  (0) 2019.05.13
[VueJS] list  (0) 2019.05.13
[VueJS] data binding  (0) 2019.05.12
[Front-end] Javascript 기초 - 1  (0) 2019.01.28
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
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
글 보관함