If the data changes in the vue-cli project data, how does the page list show the data changes before and after?

how to achieve the rise and fall of values in asynchronously acquired data like this in vue-cli?

clipboard.png

clipboard.png

clipboard.png

Mar.18,2021

there are actually some differences in requirements before and after this change.

  1. changes before and after the user refreshes the page.
  2. similar to Baidu, it has nothing to do with the user refreshing the page, and the back end calculates the rise and fall.

there is no discussion about the second requirement. Assuming that the subject of the question is the first, I will solve it like this:

after requesting new list data, don't rush to bind data, to compare the existing data with the existing data, tie the comparison result to the new data, and then update it to data.

-Separator-

for multi-layer nesting, it is also necessary to traverse and compare.
to understand that you need to rise or fall, you need data to reflect, so you can only traverse and compare with the last data.


clipboard.png

function diff(arr1, arr2) {
    return arr1.map((item, i) => Object.assign(item, {up: item.a < arr2[i].a}))
}
diff([{a: 1.2}, {a: 2.8}, {a: 3}], [{a: 1.5}, {a: 2}, {a: 2}])

A simple diff will do, return a up of Boolean type, and then set the corresponding rise and fall icon

Menu