zoukankan      html  css  js  c++  java
  • vue教程2-08 自定义键盘信息、监听数据变化vm.$watch

    vue教程2-08 自定义键盘信息

    @keydown.up
    @keydown.enter
    
    @keydown.a/b/c....
    
    自定义键盘信息:
        Vue.directive('on').keyCodes.ctrl=17;
        Vue.directive('on').keyCodes.myenter=13;
    @keydown.a/b/c....
    <input type="text" @keydown.c="show">
    自定义键盘信息:
        Vue.directive('on').keyCodes.ctrl=17;
        Vue.directive('on').keyCodes.myenter=13;
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
        </style>
        <script src="vue.js"></script>
        <script>
            Vue.directive('on').keyCodes.ctrl=17;  //
            Vue.directive('on').keyCodes.myenter=13;
            window.onload=function(){
                var vm=new Vue({
                    el:'#box',
                    data:{
                        a:'blue'
                    },
                    methods:{
                        show:function(){
                            alert(1);
                        }
                    }
                });
            };
    
        </script>
    </head>
    <body>
        <div id="box">
            <input type="text" @keydown.myenter="show | debounce 2000">
        </div>
    </body>
    </html>

    监听数据变化:
    vm.$el/$mount/$options/....

    vm.$watch(name,fnCb); //浅度

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="vue.js"></script>
        <script>
            window.onload=function(){
                var vm=new Vue({
                    el:'#box',
                    data:{
                        json:{name:'strive',age:16},
                        b:2
                    }
                });
    
                vm.$watch('json',function(){
                    alert('发生变化了');//浅监听,json里面某个属性变,是不会监听到的
                });
    
                document.onclick=function(){
                    vm.json.name='aaa';
                };
            };
    
        </script>
    </head>
    <body>
        <div id="box">
            {{json | json}}//json过滤相当于 JSON.string
            <br>
            {{b}}
        </div>
    </body>
    </html>

    vm.$watch(name,fnCb,{deep:true}); //深度监视

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="vue.js"></script>
        <script>
            window.onload=function(){
                var vm=new Vue({
                    el:'#box',
                    data:{
                        json:{name:'strive',age:16},
                        b:2
                    }
                });
    
                vm.$watch('json',function(){
                    alert('发生变化了');
                },{deep:true});
    
                document.onclick=function(){
                    vm.json.name='aaa';
                };
            };
    
        </script>
    </head>
    <body>
        <div id="box">
            {{json | json}}
            <br>
            {{b}}
        </div>
    </body>
    </html>
  • 相关阅读:
    [总结]并查集
    一些麻烦的语法知识
    P1496 找筷子
    P1314 [NOIP2011 提高组] 聪明的质监员
    HDU 1232 -畅通工程(并查集)
    POJ 1611 -The Suspects (并查集)
    方框(HPU暑期第四次积分赛)
    HDU 2191
    B
    HDU 1009
  • 原文地址:https://www.cnblogs.com/baiyangyuanzi/p/6774926.html
Copyright © 2011-2022 走看看