美文网首页
【基础】阻止默认行为

【基础】阻止默认行为

作者: JerichoPH | 来源:发表于2017-10-12 21:55 被阅读11次

    阻止默认行为

    • html
    <div>
        <p>当鼠标右键被绑定事件时,会跳出默认菜单,我们需要阻止该行为的方式</p>
        <button @contextmenu="show($event)">阻止默认行为</button>
    </div>
    
    • js
    <script>
        // 初始化数据
        window.onload = function () {
            // vue
            var vueApp = new Vue({
                el: '#app',
                data: {message: '这里是测试内容'},
                methods: {
                    show: function (event) {
                        alert(1);
                        event.preventDefault();
                    }
                }
            });
        };
    </script>
    

    相关文章

      网友评论

          本文标题:【基础】阻止默认行为

          本文链接:https://www.haomeiwen.com/subject/ddfayxtx.html