Home Web Front-end JS Tutorial Detailed explanation of vue getting input input value

Detailed explanation of vue getting input input value

Jan 15, 2018 pm 01:21 PM
input Detailed explanation enter

This article mainly introduces relevant information on how to solve the problem of Vue obtaining input input value. I hope this article can help everyone and let everyone master such problems. Friends who need it can refer to it. I hope it can help everyone.

The solution to the problem of vue getting input input value

There are multiple lines of input input boxes in v-for. How does vue get the input value of a certain line? Just write it I added some code, which means that a multi-line list collection is returned in the background. The page displays a multi-line input box. When the value of a certain row is modified, verification is performed. When inputting an error-friendly prompt, a clear button is added at the end. Click to clear the current row of data. , the initial idea is to use v-bind:value to bind the value. This will cause a situation where the value entered on the page cannot be obtained. v-bind will not modify the value in the original list, and ref cannot be dynamically bound. Definitely, ref can only be obtained in full, this.$refs.itemPriceRef[], which takes the values ​​​​of all input boxes. It is an array and can be verified before submission. However, it is impossible to determine a certain row of operations, and Vue operates DOM elements very quickly. It's very bad. I searched for a lot of information but couldn't find a way to get the value. Finally, I found that the problem was solved by directly binding the value in the list with v-model. In this way, the value in the list will be directly modified when modifying, and there will be no input. The value is different from the original value. VUE is very convenient for binding values. I just started learning Vue and I am not proficient in using it. I didn’t expect this method. It wasted a lot of time, but I also learned a lot.

PS: Summarized 3 ways to get the value of the input box on the page. The first one is to use v-bind:value + ref. This method is only suitable for specific input boxes.

For example, the login page only has an account and password input box.

2 is obtained using the v-model method. This method modifies the original list value, so when submitting, you need to traverse the original list, which is a bit troublesome.

3 uses v-model + ref, which is how I wrote it. The difference from 2 is that when submitting, ref is used directly to get the value. I feel it is more useful when there are an unknown number of input boxes.

I just summed it up casually. It is probably not worth mentioning in the eyes of the masters, but for me, a person who has just learned vue, it did waste me a long time.

Take some time to record it. Deepen your impression.


<p v-model="skuList" v-for="(val, key) in skuList "> 
<p> 
<p> 
<span>价格:</span> 
<span><input type="text" v-model="val.price" ref="priceRef" v-on:change="checkPrice(val)"></span>
Copy after login


<pre name="code" class="html"><i v-on:click="dataClearStockPrice(val)"></i></pre></p><p><span>上限:</span><span><input class="stockTotal" type="text" v-model="val.stock" ref="totalRef"v-on:change="checkStock(val)"<span style="font-family:Arial,Helvetica,sans-serif"> ></span></span> 
<pre></pre> 
<p></p> 
<pre></pre> 
<pre name="code" class="html"><span style="font-family:Arial, Helvetica, sans-serif;"><i v-on:click="dataClearStockTotal(val)"></i> 
</span></p> 
</p> 
</p></pre><pre name="code" class="html"></pre><pre name="code" class="html">    checkPrice:function (data) { 
    var priceReg = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/; 
    if(!priceReg.test(data.price)){ 
     Toast({message: "格式错误"}); 
     data.price = ""; 
    } 
   }, 
   checkStock:function (data) { 
    var totalReg = /^[0-9]*$/; 
    if(!totalReg.test(data.stock)){ 
     Toast({message: "格式错误"}); 
     data.stock = ""; 
    } 
   }, 
   dataClearStockPrice:function(data){ 
    data.price = ''; 
   }, 
   dataClearStockTotal:function(data){ 
    data.stock = ''; 
   },</pre><br data-filtered="filtered"> 
<span style="white-space:pre" data-filtered="filtered"></span> 
<pre name="code" class="html"></pre> 
<p></p> 
<p><br data-filtered="filtered"> 
</p>
Copy after login

Related recommendations:

About obtaining the attr method and prop method in jQuery Input's checked attribute operation method

Jquery various ways to obtain the value in input type=text

PHP obtains the value in the input input box The value is compared to the database and displayed

The above is the detailed content of Detailed explanation of vue getting input input value. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Disabling Win11 Input Experience Guide Disabling Win11 Input Experience Guide Dec 27, 2023 am 11:07 AM

Disabling Win11 Input Experience Guide

Windows input encounters hang or high memory usage [Fix] Windows input encounters hang or high memory usage [Fix] Feb 19, 2024 pm 10:48 PM

Windows input encounters hang or high memory usage [Fix]

Detailed explanation of obtaining administrator rights in Win11 Detailed explanation of obtaining administrator rights in Win11 Mar 08, 2024 pm 03:06 PM

Detailed explanation of obtaining administrator rights in Win11

Detailed explanation of the mode function in C++ Detailed explanation of the mode function in C++ Nov 18, 2023 pm 03:08 PM

Detailed explanation of the mode function in C++

Detailed explanation of remainder function in C++ Detailed explanation of remainder function in C++ Nov 18, 2023 pm 02:41 PM

Detailed explanation of remainder function in C++

Detailed explanation of division operation in Oracle SQL Detailed explanation of division operation in Oracle SQL Mar 10, 2024 am 09:51 AM

Detailed explanation of division operation in Oracle SQL

Detailed explanation of the role and usage of PHP modulo operator Detailed explanation of the role and usage of PHP modulo operator Mar 19, 2024 pm 04:33 PM

Detailed explanation of the role and usage of PHP modulo operator

Detailed explanation of the linux system call system() function Detailed explanation of the linux system call system() function Feb 22, 2024 pm 08:21 PM

Detailed explanation of the linux system call system() function

See all articles