vue2.0学习

2018-08-05  本文已影响0人  一包

事件深入

v-on

事件对象

事件冒泡

--- 阻止冒泡

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <script src="js/vue1.0.js"></script>
        <script>
        window.onload=function(){
            new Vue({
                el: '#box',
                methods: {
                    show: function (ev) {
                        alert(1)
                         ev.cancelBubble=true;

                    },
                    show2: function (){
                        alert(2)
                    }

                }
            })


        }
        </script>
    </head>
    <body>
    <div id="box">
        <div @click="show2()">
        <input type="button" value="按钮" @click="show($event)" />
        </div>
    </div>
    </body>
</html>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <script src="js/vue1.0.js"></script>
        <script>
        window.onload=function(){
            new Vue({
                el: '#box',
                methods: {
                    show: function (ev) {
                        alert(1)

                    },
                    show2: function (){
                        alert(2)
                    }

                }
            })


        }
        </script>
    </head>
    <body>
    <div id="box">
        <div @click="show2()">
        <input type="button" value="按钮" @click.stop="show($event)" />
        </div>
    </div>
    </body>
</html>

默认行为(默认事件)

<script src="vue.js"></script>
    <script>
        window.onload=function(){
            new Vue({
                el:'#box',
                data:{

                },
                methods:{
                    show:function(){
                        alert(1);
                    }
                }
            });
        };
    </script>
</head>
<body>
    <div id="box">
        <input type="button" value="按钮" @contextmenu.prevent="show()">
    </div>

键盘

属性

 var Box2 = new Vue({
                el: '#box2',
                data: {
                    url: 'http://e.hiphotos.baidu.com/image/w%3D500/sign=f41ccdfef1f2b211e42e854efa816511/e61190ef76c6a7ef2a3f03abf7faaf51f3de6626.jpg'
                }
            })


        }
<div id="box2">
        <img :src="url" alt="" />
    </div>

class和style

  1. :class="[a]" a是数据
<style>
        
        .big{
            font-size:100px;
        }
</style>
<script>
        window.onload=function(){
            new Vue({
                el:'#box',
                data:{
                    a:'big'
                },
                methods:{
                }
            });
        };
    </script>
<div id="box">
        <strong :class="[a]">文字...</strong>
</div>
  1. :class="[a,b,c]" 可多个class
  2. :class="{red:a, blue:false}" a是数据且为布尔值
<style>
        .red{
            color: red;
        }
        .blue{
            background: blue;
        }
    </style>
    <script src="vue.js"></script>
    <script>
        window.onload=function(){
            new Vue({
                el:'#box',
                data:{
                },
                methods:{
                }
            });
        };
    </script>
<div id="box">
        <strong :class="{red:true,blue:true}">文字...</strong>
</div>
  1. :class="json"
<style>
        .red{
            color: red;
        }
        .blue{
            background: blue;
        }
    </style>
    <script src="vue.js"></script>
    <script>
        window.onload=function(){
            new Vue({
                el:'#box',
                data:{
                    json:{
                        red:true,
                        blue:true
                    }
                },
                methods:{
                }
            });
        };
    </script>
<div id="box">
        <strong :class="json">文字...</strong>
</div>
  1. :style="[c]"
  2. :style="[c,d]"
  3. :style="json"
  4. 注意: 复合样式,采用驼峰命名法

模板

过滤器:-> 过滤模板数据

<div id="box">
        {{12|currency '¥'}}
</div>
上一篇 下一篇

猜你喜欢

热点阅读