VUE自定义指令

<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8'>
    <title>Vue</title>
    <script src='../js/vue.js'></script>
</head>

<body>
    <div id='app'>
        <h2>{{n}}</h2>
        <h2><span v-big="n"></span></h2>
        <button @click="n++">n+1</button>
        <input type="text" v-finput="n">
    </div>
    <script>
        new Vue({
            el: '#app',
            data: {
                message: 'Hello Vue.js!',
                n: 1,
            },
            directives: {
                // 指令 绑定时   和  模板在重新解析时被调用
                big(el, binding) {
                    console.log("big");

                    el.innerText = binding.value * 10;
                },
                finput: {
                    // 绑定时
                    bind(el, binding) {
                        console.log("binding");
                        el.value = binding.value
                    },
                    // 生成到界面时
                    inserted(el, binding) {
                        console.log("inserted");
                        el.focus()
                    },
                    // 更像时
                    update(el, binding) {
                        el.value = binding.value
                        console.log("updata");
                    },

                }
            }
        })
    </script>
</body>

</html>
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容