Vue 正在改变集合的顺序

Vue is changing collection's order

我有一个正在使用和 sortByDesc('created_at') 进行排序的集合。当我 dd() 它返回到我的视图之前,它改变了顺序。

但是,一旦我将它传递给我的 vue 组件,它就会改回顺序。

为什么会这样?有办法解决吗?

我一直都忘记了这一点,但这通常是因为集合排序方法保留了它们的键。引用文档 (https://laravel.com/docs/5.6/collections#method-sortby):

The sortBy method sorts the collection by the given key. The sorted collection keeps the original array keys, so in this example we'll use the values method to reset the keys to consecutively numbered indexes: