In v-for, Vuejs uses index to add class to the first item, vuejsv-

Source: Internet
Author: User

In v-for, Vuejs uses index to add class to the first item, vuejsv-

(1) In v-for, use index to add class to the first item

View the CODE piece derived from my CODE piece on CODE

<A class = "list-group-item": class = "{'activity ':! Index} "v-for =" (I, index) in announcement ">

Index comes from v-for. I indicates the elements of the traversal array, and index indicates the index.

Since index starts from 0, if you want to specify that the first item has the active class, use v-bind: class = "{'activity ':! Index }"

The first item is originally false (0), the second item is true (> 0), and then the value is reversed through logical non-operators.

Therefore, the first item has the active class, but does not follow it.

If a class exists except the first one, it can be achieved by not adding logical non-operators.

Similarly, you can use an expression like index = 2 to obtain the class from the third item.

Note,My version is Vuejs2.0, so it seems that I cannot use $ index to replace it.

In v-for, the method of using index to add class to the first item is to share all the content with you in the small series. I hope to give you a reference, we also hope that you can support the customer's home.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.