v-show自定义指令

2018-07-07  本文已影响0人  嗯哼_3395

v-show

<!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){
              if(binding.value){
                 el.style.display="block"
              }else{
                 el.style.display="none"
              }

           },
           update:function(el,binding){
              if(binding.value){
                 el.style.display="block"
              }else{
                 el.style.display="none"
              }
           }


        })
       var box=new Vue({
          el:"#box",
          data:{
              flag:true
          }
       })

    </script>
</html>
上一篇下一篇

猜你喜欢

热点阅读