Summary of Vue.js form control operations

亚连
Release: 2018-05-28 15:05:53
Original
1620 people have browsed it

This article introduces you to the relevant knowledge of Vue.js form control operation. This article demonstrates the method of using v-model in input and textarea elements through examples. This article introduces you very well and has reference value. Friends who need it can refer to it

Concept Description

v-model command: Create two-way data binding on the form control element. v-model will automatically choose the correct method to update the element based on the control type.

Input box

The example demonstrates the use of v-model in the input and textarea elements to achieve bidirectionality Data binding:

HTML

    Vue 测试实例 - 菜鸟教程(runoob.com)  

input 元素:

消息是: {{ message }}

textarea 元素:

{{ message2 }}

Copy after login

The effect is as shown in the figure:

Complex Check box

If the check box is a single one, it is a logical value. If there are multiple check boxes, it is bound to the same array:

HTML

    Vue 测试实例 - 菜鸟教程(runoob.com)  

单个复选框:

多个复选框:


选择的值为: {{ checkedNames }}

Copy after login

The effect is as shown:

Radio button

##HTML

    Vue 测试实例 - 菜鸟教程(runoob.com)  



选中值为: {{ picked }}

Copy after login

The effect is as shown:

drop-down list

HTML

    Vue 测试实例 - 菜鸟教程(runoob.com)  

选择的网站是: {{selected}}

Copy after login

The effect is as shown:

##Modifier.lazy

By default, v-model synchronizes the value and data of the input box in the input event, but you can add a modifier lazy to switch to synchronization in the change event:

 
Copy after login

.number

If you want to automatically convert the user's input value to the Number type (if the conversion result of the original value is NaN, the original value will be returned), you can add a modifier number to v-model To handle input values:

Copy after login

This is often useful because input values in HTML will always be returned as string types when type="number".

.trim


If you want to automatically filter the first and last spaces input by the user, you can add the trim modifier to v-model to filter the input:

Copy after login

The above is what I compiled for everyone. I hope It will be helpful to everyone in the future.

Related articles:

Collection of methods to disable ajax caching in (ASP/PHP/JSP/html/js)

ajax Methods of using actions with different namespaces

Use ajax to preview the link and you can see the content of the link

The above is the detailed content of Summary of Vue.js form control operations. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!