Detailed explanation of Vue event handling and event modifiers

Detailed explanation of Vue event handling and event modifiers

insert image description here

insert image description here

 <div id="root">
        <h2>Keep going, {{name}}! </h2>
        <!-- Prevent default events -->
        <a @click.prevent="showInfo" href="https:www.baidu.com">Click me for prompt information</a>
        <!-- Prevent event bubbling -->
        <div class="demo1" @click="showInfo">
            <button @click.stop="showInfo">Click me for information</button>
        </div>
        <!-- Event is triggered only once -->
        <button @click.once="showInfo">Click me for information</button>
        <!-- Use event capture mode -->
        <div class="box1" @click.capture="showMsg(1)">
            div1
            <div class="box2" @click="showMsg(2)">
                div2
            </div>
        </div>
        <!-- The event is triggered only when event.target is the element currently being operated on -->
        <div class="demo1" @click.self="showInfo">
            <button @click="showInfo">Click me for info</button>
        </div>
    </div>
    <script>
        Vue.config.productionTip = false;
        new Vue({
            el: '#root',
            data() {
                return {
                    name: 'Zhang San'
                }
            },
            methods: {
                showInfo(e) {
                    // e.preventDefault();
                    alert('Hello, Mr. Wang!')
                },
                showMsg(msg) {
                    console.log(msg);
                }
            }
        });
    </script>

insert image description here

Summarize

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of Vue's click event anti-shake and throttling processing
  • Detailed explanation of Vue event handling principle and process
  • Detailed explanation of Vue event handling
  • Summary of event handling in Vue.js front-end framework
  • Vue3 Vue Event Handling Guide
  • Introducing mousewheel events and compatibility processing in Vue
  • Details of event handling in Vue

<<:  HTML checkbox Click the description text to select/uncheck the state

>>:  25 Tools to Improve Website Usability and Conversion Rates

Recommend

Detailed explanation of MySQL syntax, special symbols and regular expressions

Mysql commonly used display commands 1. Display t...

CSS menu button animation

To write a drop-down menu, click the button. The ...

A brief introduction to MySQL storage engine

1. MySql Architecture Before introducing the stor...

Solution to the CSS height collapse problem

1. High degree of collapse In the document flow, ...

A must-read career plan for web design practitioners

Original article, please indicate the author and ...

Layim in javascript to find friends and groups

Currently, layui officials have not provided the ...

Detailed tutorial on deploying Jenkins based on docker

0. When I made this document, it was around Decem...

Steps to install MySQL on Windows using a compressed archive file

Recently, I need to do a small verification exper...

When to use table and when to use CSS (experience sharing)

The main text page of TW used to have a width of 8...

Nodejs uses readline to prompt for content input example code

Table of contents Preface 1. bat executes js 2. T...

Ideas and practice of multi-language solution for Vue.js front-end project

Table of contents 1. What content usually needs t...

CSS transparent border background-clip magic

This article mainly introduces the wonderful use ...

A small introduction to the use of position in HTML

I just learned some html yesterday, and I couldn&#...