Vue. js moves the array position and updates the view method. The vue. js Array

Source: Internet
Author: User

Vue. js moves the array position and updates the view method. The vue. js Array

Use vue. js v-for to bind several options. You need to sort and move the options up and down.

The position of the array in options needs to be exchanged, which is usually written as follows:

Suppose to move one forward:

Var index = this. options. indexOf (option); // obtain the index of the current option object in the array. Var tempOption = this. options [index-1]; // store the previous one. options [index-1] = option; (this. options [index]) this. options [index] = tempOption;

In this way, the order of the array is indeed changed, but the view is not updated and moved. For details, see the vue official website array description.

One solution is to change the object and use the vue's set method:

Var index = options. indexOf (option); var tempOption = options [index-1]; Vue. set (options, index-1, options [index]); Vue. set (options, index, tempOption );

The above vue. js moves the array location, and the method for updating the view is all the content that I have shared with you. I hope to give you a reference, and I hope you can provide more support for the customer's house.

Related Article

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.