自定义指令传参

<div v-pin:xxx.bottom.right="card1.pinned"  :class="liked">111
    <button @click="card1.pinned = !card1.pinned"></button>
</div>
Vue.directive('pin',function (el,binding) {
    var el = el; //el代表所在元素

//v-pin:xxx.bottom.right="card1.pinned"

var val = binding.value; //card1.pinned中的card1.pinned对应data值 例子中是true或false var position = binding.modifiers; //bottom和right var warning = binding.arg; //xxx console.log("val:",warning) if(val){ el.style.position = 'fixed'; for(var P in position){ // console.log(P) if(position[P]){ console.log([P])

el.style[P] = '10px'

} } if(warning ==='xxx'){ el.style.background = 'yellow' } }else { el.style.position = 'static'; } }) var app = new Vue({ el:"#app", data:{ liked:'liked', card1:{ pinned:false } } })
阅读更多
上一篇component传值问题
下一篇mixins
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭