Vue event's $event parameter = event value case

Vue event's $event parameter = event value case

template

<el-table :data="dataList">
 <el-table-column label="id" prop="id"></el-table-column>
 <el-table-column label="name" prop="name">
 <template v-slot="props">
  <el-input-number
  :min="0"
  v-model="props.row.count"
  @change="updateProduct($event)"
  size="mini"
 ></el-input-number>
 </template>
 </el-table-column>
</el-table>

Script Section

export default {
 data() {
 return {
  dataList: [
  { id: 1, name: '001', count: 1 },
  { id: 2, name: '002', count: 2 },
  { id: 3, name: '003', count: 3 },
  ]
 }
 },
 methods: {
 updateProduct(value) {
  console.info(value)
 }
 }
}

Supplement: Vue learning notes: The role of $event object in events

In Vue, click events or other events can be added to the event to obtain the DOM of the tag element or modify the attributes of the tag, etc. The specific usage is as follows:

1. You can get the DOM element through $event

html:

<button data-get="Data button" @click="getRvent($event)">Get event object</button>

First, let's print the $event object to see what properties it has, as shown below

The srcElement is the current label element, and you can use this attribute to get the label element of the current click event.

For example, we can operate on the obtained elements, just like native js, as follows:

 // Get the event object e
 getRvent(e){
  console.log(e);
  e.srcElement.style.background="red";
 }

Before clicking:

After clicking:

2. In addition, we can also modify the properties of the tag itself, such as changing the text value of a button. At this time, we use the textContent under $event to modify it.

Before clicking the button:

After clicking the button:

3. We can also get the attribute value of the tag customization through $event, as follows:

HTML code:

<button data-get="Data button" @click="getRvent($event)">Get event object</button>

This button tag has a custom attribute data-get, at this time we can get it according to the attribute target.dataset.get of $event

You can print it on the console as follows:

In fact, sometimes we can use the attributes of the element itself to perform operations, abandon operations such as adding classes, reduce code redundancy, and refine the code.

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Usage and precautions of EventBus in Vue components
  • vue v-for clicks on the current row to get the current row data and the operation of the event current event object
  • A brief discussion on the understanding of $event in Vue and the inclusion of default values ​​in the framework
  • Using Vue's EventBus bus mechanism in Uni
  • Description of event trigger ($emit) and event Bus ($on) between Vue components
  • Detailed explanation of using eventemitter2 to realize Vue component communication
  • Detailed implementation code of Vue communication method EventBus

<<:  Example of how to build a Mysql cluster with docker

>>:  MySql Sql optimization tips sharing

Recommend

MySQL 5.7 installation and configuration tutorial under CentOS7 (YUM)

Installation environment: CentOS7 64-bit, MySQL5....

Native JS to implement hover drop-down menu

JS implements a hover drop-down menu. This is a s...

How to use Linux to calculate the disk space occupied by timed files

Open the scheduled task editor. Cent uses vim to ...

linux No space left on device 500 error caused by inode fullness

What is an inode? To understand inode, we must st...

Vue.js style layout Flutter business development common skills

Correspondence between flutter and css in shadow ...

A brief introduction to VUE uni-app basic components

1. scroll-view When using vertical scrolling, you...

JavaScript implements page scrolling animation

Table of contents Create a layout Add CSS styles ...

Set an icon for the website to be displayed on the far left of the browser tab

What is the purpose of this sentence? Copy code Th...

MySQL 8.0.19 Installation Tutorial

Download the installation package from the offici...

Detailed steps to install Docker 1.8 on CentOS 7

Docker supports running on the following CentOS v...

MySQL FAQ series: When to use temporary tables

Introduction to temporary tables What is a tempor...

How to use Portainer to build a visual interface for Docker

Portainer Introduction Portainer is a graphical m...

Vue+openlayer5 method to get the coordinates of the current mouse slide

Preface: How to get the coordinates of the curren...