js 同一接口,合并多次请求


<html>
<title>新标签页111</title>

<body>
  <script>
  //正则判断字符串开头abc和结尾xyz(/^(abc)(.+)?(xyz)$/).test('abcxyz')
    async function fun1() {
      var newlist = [];
      var index = 4;
      for (var i = 0; i < index; i++) {
        const params = {
          CellID:i,
          Offset: i,
          Count:i,
          RankID:i,
        };
        var res = await requst(params)
        console.log(res, 'res')
        newlist = [...newlist, ...res.list]
        console.log(newlist, 'newlist')
        if (i == index - 1) {
          console.log(newlist)
          
        }
      }
    }

    function requst(params) {
      return new Promise((reslove, reject) => {
        setTimeout(function () {
          console.log(params,'params')
          var random = Math.ceil(Math.random() * 10)
          console.log(random, 'random')
          var res = {
            list: [{ name: "王" + random }],
          }
          reslove(res)
        }, 1000)
      })

    }
    fun1()
  </script>
</body>

</html>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM