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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器