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

Summarize the common application problems of XHTML code

<br />For some time, I found that many peopl...

Solve the problem of combining AND and OR in MySQL

As shown below: SELECT prod_name,prod_price FROM ...

Vue ElementUI Form form validation

Form validation is one of the most commonly used ...

Detailed explanation of component communication in react

Table of contents Parent component communicates w...

Modification of the default source sources.list file of ubuntu20.04 LTS system

If you accidentally modify the source.list conten...

Basic usage of custom directives in Vue

Table of contents Preface text 1. Global Registra...

Eight examples of how Vue implements component communication

Table of contents 1. Props parent component ---&g...

How to implement DIV's blur function

Use anti-shake to make DIV disappear when the mou...

Summary of MySQL slow log related knowledge

Table of contents 1. Introduction to Slow Log 2. ...

Implementation of vue-nuxt login authentication

Table of contents introduce Link start Continue t...

Vue3+el-table realizes row and column conversion

Table of contents Row-Column Conversion Analyze t...

A Brief Analysis of MySQL Connections and Collections

Join query A join query refers to a matching quer...

Several ways to shut down Hyper-V service under Windows 10

When using VMware Workstation to open a virtual m...