这篇文章主要介绍了简单了解vue数组的常用操作,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 。
``
`` //数据去重复 const unique=(arr1)=>{ const res = new Map(); return arr1.filter((a) => !res.has(a.siteId) && res.set(a.siteId, 1)) }, //冒泡排序 const bSort=(arr)=>{ var len = arr.length; for (var i = 0; i < len-1; i++) { for (var j = 0; j < len - 1 - i; j++) { // 相邻元素两两对比,元素交换,大的元素交换到后面 if (arr[j] > arr[j + 1]) { var temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } return arr; } //传入日期判断第几周 const handleYearWeek =(dt)=>{ let d1 = new Date(dt); let d2 = new Date(dt); d2.setMonth(0); d2.setDate(1); let rq = d1-d2; let days = Math.ceil(rq/(24*60*60*1000)); let num = Math.ceil(days/7); return num; } //同步请求接口 const PromiseForEach=(arr,cb)=>{ let realResult = [] let result = Promise.resolve() arr.forEach((a, index) => { result = result.then(() => { return cb(a).then((res) => { realResult.push(res) }) }) }) return result.then(() => { return realResult }) } /*同步方法调用*/ let mval=this.parameter.Month.split("-"); this.$GlobalFun.PromiseForEach(_self.waterData, (i) => { return new Promise((resolve, reject) => { setTimeout(() => { let attribute = { type:'2', siteId: i.siteId, monitorTime: mval[1], level:'5', year:mval[0] }; API_REPORT.detailInfo(attribute).then(result => { if(result.code == '200'){ this.tableData.push(result.data); waterDataindex++; if(waterDataindex==_self.waterData.length){ for(let j=0;j<result.data.length;j++){ if(result.data[j].indexNum.toFixed(2)>1){ this.tarpol.push(result.data[j]) } } } }else{ return false; } }) return resolve(i); }, 100); }) }).then((data) => { }).catch((err) => { console.log("失败"); });
相关推荐:
https://www.imooc.com/zt/v
https://www.imooc.com/zt/3229
https://www.imooc.com/zt/4252
https://www.imooc.com/zt/3251