【vue】自定义指令

//自定义函数 指令
//.vue
<div v-AA:BB="'CC'" >
 
//.vue局部指令
directives: {
  AA: {
    bind(el, binding, vnode) {
      el.style.color = "#" + Math.random().toString(16).slice(2,8);//彩色
    }
  },
}
 
//main.js全局指令
Vue.directive('AA', {
  bind(el, binding, vnode) {
    if (binding.value == "CC") {
      el.style.maxWidth = "1260px";
    } else if (binding.value == "DD") {
      el.style.maxWidth = "560px";
    }
    if (binding.arg == 'BB') {
      el.style.background = "#6677cc";
      el.style.padding = "20px";
    }
  }
})

猜你喜欢

转载自www.cnblogs.com/lovelingtaste/p/10648184.html