Home >Web Front-end >JS Tutorial >How to check the first one in the v-for loop checkbox by default through vue?

How to check the first one in the v-for loop checkbox by default through vue?

亚连
亚连Original
2018-06-01 16:06:584727browse

Below I will share with you an implementation method based on vue v-for loop checkbox-the first one is checked by default. It has a good reference value and I hope it will be helpful to everyone.

Application scenario: When making multiple selections, the first one is generally displayed by default.

Implementation method: pure vue implementation

Example:

<span v-for="(one,index) in site"><input type="checkbox" :checked="index == 0" style="vertical-align: middle;"><label>{{one.name}}</label></span>

//:checked="index == 0"为索引为0的,即为第一个复选框添加属性。

Extension: The check box that is selected by default only needs to be specified by index.

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

Related articles:

Vue-cli development environment method to implement cross-domain requests

Angular5 tags for the component itself Method of adding style class

Sample code for Vue to implement internal component carousel switching effect

The above is the detailed content of How to check the first one in the v-for loop checkbox by default through vue?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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