分享一个小知识点,不通过后端sql语句排序,借助前端接收后端的数组进行排序:

根据数组中的时间段排序

 DemandApi.query(this.queryParam)
        .then((res) => {
            res.data.list.sort((a, b) => new Date(a.createTime).getTime() - new 
            Date(b.createTime).getTime()) //这是升序,倒序的话翻过来
            this.tableData = res.data.list
        })
        .catch((err) => {
          // 通过catch捕获错误消息
          return err
        })

其中res.data.list是后端返回数组,借助sort函数进行排序,createTime数组中的时间字段,根据createTime进行升序。

Logo

前往低代码交流专区

更多推荐