dongyied24121 2019-05-23 12:23
浏览 223
已采纳

如何防止axios按键排序?

I would like the years to still be displayed desc order. In my request, the years and correctly sorted.

My PHP controller returns a json like this:

{  
   "2018":[  
      {  
         "id":25071,

      },
      {  
         "id":35037,
      }
   ],
   "2017":[  
      {  
         "id":20449,
      },
      {  
         "id":25797
      }
   ],
   "2016":[  
      {  
         "id":20419,
      },
      {  
         "id":25778
      }  
   ]
}

But when I get in in my vue component

getYears: function(){
    axios.get('/blablabla/').then(
        response => {
            console.log(response.data);
            this.years=response.data;
        }
    );
}

I get this result

{2008: Array(1), 2010: Array(5), 2011: Array(7), 2012: Array(7), 2013: Array(4), 2014: Array(5), 2015: Array(8), 2016: Array(4), 2017: Array(6), 2018: Array(6)} 2008: (...) 2010: (...) 2011: (...) 2012: (...) 2013: (...) 2014: (...) 2015: (...) 2016: (...) 2017: (...) 2018: (...)

How can I prevent it to change the order?

Thanks a lot!

  • 写回答

1条回答 默认 最新

  • drgweamoi473182981 2019-05-23 12:55
    关注

    Thats not an axios problem. In ES2015 non-integer keys where returned in insertion order. Browser things. You made it into a string, so its not an integer anymore.

    If you want to read more about it: click here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试