1. Listening for events You can use The sample code is as follows: <div id="app"> <p>{{counter}}</p> <button @click="counter += 1">+1</button> <button @click="subtract(10)">-10</button> </div> <script> const app = new Vue({ el: "#app", data: { counter: 0 }, methods: { subtract(value){ this.counter -= value } } }) </script> 2. Pass in event parameters If you want to get the native The sample code is as follows: <button v-on:click="subtract(10,$event)">Subtract 10</button> ... <script> ... methods: { subtract: function(value,event){ this.count -= value; console.log(event); } } ... </script> 3. Event modifiers It is a very common requirement to call To solve this problem,
Case 1: Prevent click events from propagating further<div id="app"> <div @click="divClick"> 1111 <button @click.stop="btnClick">Button</button> </div> </div> <script> let app = new Vue({ el: "#app", data: { count: 0 }, methods: { divClick(){ console.log("divClick") }, btnClick(){ console.log("btnClick") } } }); </script> Case 2: Submit event no longer reloads the page<div id="app"> <form action=""> <label> <input type="text"> </label> <label> <input type="submit" value="Submit"> </label> </form> </div> <script> const app = new Vue({ el: "#app", data: { } }) </script> The above is the most standard code for submitting data. After submission, it will automatically jump to Baidu. However, there is a requirement now. We hope that after entering the data, it will not automatically jump to Baidu, but process the data by our own method first, and then jump to the specified page after processing. The code is as follows: <div id="app"> <form action="https://www.baidu.com"> <label> <input type="text"> </label> <label> <input type="submit" value="Submit" @click.prevent="testClick"> </label> </form> </div> <script> const app = new Vue({ el: "#app", methods: { testClick(){ } } }) </script> Here we bind a click event to This is the end of this article about the use of Vue v-on directive. For more relevant Vue v-on directive content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: In-depth explanation of hidden fields, a new feature of MySQL 8.0
>>: Web page HTML code: production of scrolling text
Table of contents Preface 1. Install the service ...
Hello everyone, today we will talk about how to u...
If you are a software developer, you must be fami...
Will mysql's IN invalidate the index? Won'...
1. Achieve the effect 2 Knowledge Points 2.1 <...
Source: http://www.ruoyi.vip/ import Vue from ...
Table of contents 1. Create a redis docker base i...
Preface I believe everyone is familiar with addin...
background Before starting the article, let’s bri...
The final effect is as follows: The animation is ...
Good database specifications help reduce the comp...
1. Introduction to compression and packaging Comm...
What is a covering index? Creating an index that ...
This article example shares the specific code of ...
Win2008 R2 zip format mysql installation and conf...