1. Function BindingYou can use v-on:click="methodName" or the shortcut @click="methodName" to bind the event handler function @click="methodName()" is also OK. @click="methodName" is probably a shorthand. <div v-on:click="add">{{ count }}</div> <div @click="add">{{ count }}</div> data() { return { count: 0, }; }, methods: { add() { this.count++; }, }, 2. With parameters and $eventYou can pass parameters and $event directly to the event binding function <div @click="set(0, $event)">{{ count }}</div> data() { return { count: 0, }; }, methods: { add() { this.count++; }, set(value, event) { console.log(event); this.count = value; }, }, 3. Binding multiple functions to one eventMultiple functions are separated by commas. Even if there is no parameter in the function, parentheses must be added, otherwise the function will not be executed. For example, <div @click="set(0, $event), log">{{ count }}</div> will only execute set <div @click="set(0, $event), log()">{{ count }}</div> data() { return { count: 0, }; }, methods: { add() { this.count++; }, log() { console.log("log---"); }, set(value, event) { console.log(event); this.count = value; }, }, 4. Event modifiersWhen using modifiers, order is important; the corresponding code will be generated in the same order
5. Key Modifiers
6. System modifier keysThe modifier key must be pressed when the event is triggered
.exact Modifier
Mouse Button Modifiers<button @click.left="log('left cllilck')">Left click of the mouse</button> <button @click.right="log('right cllilck')">Right click</button> <button @click.middle="log('middle cllilck')">middle click</button> SummarizeThis article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: CSS mimics remote control buttons
>>: Detailed steps to install Docker mongoDB 4.2.1 and collect springboot logs
"Grand" are probably the two words that ...
A large part of data management is searching, and...
Last time, we came up with two header layouts, on...
Preface In the previous interview process, when a...
What is "Sticky Footer" The so-called &...
Payment countdown to return to the home page case...
Preface For production VPS with public IP, only t...
Copy code The code is as follows: @charset "...
In order to solve the problem mentioned last time...
Congratulations on finally convincing your bosses...
background: I have done a project before, which r...
The root account of mysql, I usually use localhos...
Today, when installing nginx on the cloud server,...
This article example shares the specific code of ...
background Today, while cooperating with other pr...