vue自定义指令实现表单获取焦点

也就是官网案例:
 
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

 

  <div id="app">
    <input type="text" v-focus>
  </div>
  <script src="../js/vue.js"></script>
  <script>
    Vue.directive('focus',{
      inserted:function(el){
        // el 表示指令所绑定的元素
        el.focus()
      }
    });
    var vm = new Vue({
      el:"#app",
      data:{
      },
      methods: {
        handle:function(){
        }
      },
      
    })

 

  </script>
</body>
</html>
posted @ 2020-06-10 23:37  _魔鬼在人间  阅读(760)  评论(0)    收藏  举报