3.阻止事件冒泡和默认行为

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>阻止事件冒泡和默认行为</title>
    <script src="js/vue.js"></script>
    <script>
        window.onload=function(){
            let vm=new Vue({
                el:'#itany',
                methods:{ 
                    show(){
                        console.log(111);
                    },
                    print(){
                        console.log(222);
                    },
                    write(){
                        console.log(333);
                    },

                    study(){
                        console.log(444);
                    }
                }
            });
        }
    </script>
</head>
<body>
    <div id="itany">
        <div @click="write">
            <p @click="print">
                <button @click.stop="show">点我</button>
            </p>
        </div>
        <hr>
        <a href="#" @click.prevent="study">俺是链接</a>
    </div>
</body>
</html>

评论

暂无评论