20-基础-自定义指令-局部自定义指令


<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width,initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='ie=edge'>
    <title>Document</title>
</head>

<body>
    <div id='app'>
        <input type="text" v-focus>
    </div>
    <script src='./vue.js'></script>
    <script>
        new Vue({
            el: '#app',
            data: {},
            // // 局部自定义指令
            // // 1. 定义 (通过选项)
            // // 2. 功能
            // // 3. 使用
            directives: {
                // 指令名字:{inserted:function(el){}}
                focus: {
                    inserted: function (el) {
                        el.focus();
                    }
                }
            },
            methods: {}
        });
    </script>
</body>

</html>
posted @ 2019-05-28 21:53  193557749  阅读(553)  评论(0编辑  收藏  举报