Vue array operation does not refresh the resolution of the view problem

Source: Internet
Author: User

Recently using the VUE2.0 development project, there is a list that uses v-for to bind to an array, using the push, splice, this, and so on Vue's recommendation. $set three mutation methods to manipulate the array. Found in the Add page, three methods will be able to refresh the view in a timely manner, but in the modified page, only this. $set method to modify the array elements can be refreshed, the other two methods do not refresh the view, using Vue-devtools view, the data can be successfully modified.

Try to use the push method in the Mount phase to add one by one, try to use the object to display the definition field properties, try Baidu to the N method ... It took four or five hours, no! But the problem must be that there is no condition that triggers the Vue refresh view.

Finally, a manual forced refresh is simulated:

1. Add a hidden to the HTML and bind to a flag field:

2. The Mount stage assigns the initial value to flag:

3. After push and splice, change the value of flag!!!

Idea: Because flag is a simple field, its change is sure to refresh the view, so by changing the flag, manually refresh the view.

Thus, the view refresh of Vue is a whole refresh, not just the changed fields.

Vue array operation does not refresh the resolution of the view problem

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.