天天看點

vue再讀43-局部自定義指令

<!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>
<style>
 
</style>
 
<body>
    <!-- 全局自定義指令 -->
    <div id="abc">
        <input type="text" v-focus>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        /*  Vue.directive('focus', {
                            inserted(el) {
                                //該自定義指令的調用者
                                el.focus();
                            }
                        }) */
        var vm = new Vue({
            el: '#abc',
            //模闆ajax傳回的資料
            data: {
                count: "geyao"
            },
            //局部自定義指令
            directives: {
                focus: {
                    inserted(el) {
                        el.focus();
                    }
                }
            },
            methods: {
 
            },
 
 
        })
    </script>
    <!-- 清單渲染 -->
    <!-- 1渲染數組 -->
    <!-- 2c處理無資料的時候 -->
</body>
 
</html>      
vue再讀43-局部自定義指令