v-if判断指令
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="vue.min.js"></script>
</head>
<body>
<div id="box">
<p v-veb="flag">hello</p>
</div>
</body>
<script>
Vue.directive("veb",{
inserted:function(el,binding){
//删除之后找不到它的父节点,需要存一下
el.pd=el.parentNode;
if(!binding.value){
el.parentNode.removeChild(el)
}
},
update:function(el,binding){
if(binding.value){
el.pd.appendChild(el)
}else{
el.parentNode.removeChild(el)
}
}
})
var box=new Vue({
el:"#box",
data:{
flag:true
}
})
</script>
</html>
网友评论