Vue.JS 2 Tutorial #34 - Custom Directives > JS프레임워크

JS프레임워크

Vue.JS 2 Tutorial #34 - Custom Directives 정보

Vue Vue.JS 2 Tutorial #34 - Custom Directives

본문

Custom Directives

 

directives : v-if, v-show, v-model, vi-on 등

 

Vue.directive('rainbow', {

  bind(el, binding, vnode) {

    el.sytle.color = "#" + Math.random().toString().slice(2, 8);

  }

});

 

<h2 v-rainbow>{{ blog.title }}</h2>  ==> 전체가 el

v-rainbow="""에 들어가는 것이 있다면 그것이 binding

 

v-theme:column = "'wide'"

directive: argument = binding

 

Vue.directive('theme', {

  bind(el, binding, vnode) {

    if(binding.value == 'wide') {

      el.style.maxWidth = "1200px";

    } else if (binding.value == 'narrow') {

      el.style.maxWidth = "560px"

    }

    if(bingidng.arg == 'column') {

      el.style.background = '#ddd';

      el.style.padding = '20px';

    }

  }

});

 

 

 

추천
0
  • 복사

댓글 0개

© SIRSOFT
현재 페이지 제일 처음으로