zoukankan      html  css  js  c++  java
  • vue事件

    1、v-on:click 单击事件

    <!DOCTYPE html>
    <html>
    <head>
        <title>Page Title</title>
        <script src = "vue.js"/>
        <script>
            var c = new Vue({
                el:'#box',
                data:{
                    arr:['a','b','c','d']
                },
                methods:{
                    show:function(){
                        alert(1);
                    },
                    add:function(){
                        this.arr.push('e')
                    }
                }
            });
        </script>
    </head>
    <body>
            <div id = "box">
                <input type = "button" value = "button" v-on:click="show()">
                <input type = "button" value = "button" v-on:click="add()">
           <br>
            <ul><li v-for = "value in arr">{{value}}</li></ul>
    </div> </body> </html>

    v-on:mouseover、mouseout、mousedown、mouseup、dblclick....

    2、v-show = "true/false" 显示、隐藏

    <!DOCTYPE html>
    <html>
    <head>
        <title>Page Title</title>
        <script src = "vue.js"/>
        <script>
            var c = new Vue({
                el:'#box',
                data:{
                    arr:['a','b','c','d'],
                    a:true
                },
                methods:{
                    show:function(){
                        alert(1);
                    },
                    add:function(){
                        this.arr.push('e')
                    }
                }
            });
        </script>
    </head>
    <body>
            <div id = "box">
                <input type = "button" value = "button" v-on:click="a=false">
                <input type = "button" value = "button" v-on:click="add()"  v-show="a">
            </div>
    </body>
    </html>

    补充:

    v-on:click    简写: @click

     事件对象:

      @click = "show($event)"

    事件冒泡:子事件结束后父事件相继冒泡执行

      阻止事件冒泡:

        1、event.cancelBubble = true;

        2、@click.stop = "show()"  //推荐

    默认事件

        @contextmenu = "show($event)" //右击事件,右击浏览器会默认弹出菜单

      阻止默认事件:

        1、event.preventDefault();

        2、@contextmenu.prevent = "show()"

    键盘事件

      @keydown = "show($event)"   @keyup

      show:function(ev){

        alert(ev.keyCode);  

      }

      常用键:

        回车    @keyup.13 @keyup.enter

        上,下,左,右  up,down,left,right

  • 相关阅读:
    软件测试理论基础
    使用Pycharm官方统计代码行插件统计代码总行数
    Jmeter的配置文件解析
    python异常整理
    python2与python3的区别
    tomcat的server.xml配置
    异常:Error response from daemon: conflict: unable to delete 6fa48e047721 (cannot be forced)
    前端 -- 定位和z-index
    前端 -- background
    前端 -- 超链接导航栏案例
  • 原文地址:https://www.cnblogs.com/hyl-home/p/8571274.html
Copyright © 2011-2022 走看看