Use Vuex for data processing
But when loading data, I need to sort it. My approach is
In Getter
curProductLists: state => state.products.sort(true)
But when opening the page, an error message appears:
[Vue warn]: Error in render function: "TypeError: Cannot read property 'sort' of undefined"
found in
When you click on the menu and go to the page, the page data comes out. When F5 is refreshed, an error will be reported. I think this is because the data is sorted before it is loaded into the data. Is there any solution to this problem?
Put the sorting operation into mutation, load data in action (asynchronous operation), and commit mutation in its callback
Refer to the sample code in the shopping cart in the official documentation