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

CSS isolation issue in Blazor

1. Environment VS 2019 16.9.0 Preview 1.0 .NET SD...

Solution to the problem of MySQL deleting and inserting data very slowly

When a company developer executes an insert state...

mysql installer community 8.0.12.0 installation graphic tutorial

This tutorial shares the installation of mysql in...

How to use CSS to pull down a small image to view a large image and information

Today I will talk about a CSS special effect of h...

How to build php-nginx-alpine image from scratch in Docker

Although I have run some projects in Docker envir...

10 ways to view compressed file contents in Linux (summary)

Generally speaking, when we view the contents of ...

Vant+postcss-pxtorem implements browser adaptation function

Rem layout adaptation The styles in Vant use px a...

Detailed explanation of samba + OPENldap to build a file sharing server

Here I use samba (file sharing service) v4.9.1 + ...

HTML form submission method case study

To summarize the form submission method: 1. Use t...

Detailed explanation of the cache implementation principle of Vue computed

Table of contents Initialize computed Dependency ...

Examples of implementing progress bars and order progress bars using CSS

The preparation for the final exams in the past h...

Detailed explanation of overflow-scrolling to solve scrolling lag problem

Preface If you use the overflow: scroll attribute...

In-depth analysis of MySQL database transactions and locks

Table of contents 1. Basic Concepts ACID 3.AutoCo...

Summary of the use of TypeScript in React projects

Preface This article will focus on the use of Typ...

Full steps to create a high-performance index in MySQL

Table of contents 1. Index Basics 1. Types of Ind...