Vuex sort in getters but prompts undefind
漂亮男人
漂亮男人 2017-06-15 09:23:40
0
1
937

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?

漂亮男人
漂亮男人

reply all(1)
黄舟

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template