日常踩坑日记

1、移动端写一个H5页面,使用Jq $.ajax 没有做任何封装,请求接口时 使用CDN方式引入 vConsole v3.14.0版本会造成token userId无法赋值到headers里面造成请求失败,返回没有登录
2、判断 某个变量 newPrice 当 !newPrice 生效时, newPrice=0 也生效
3、PC端下载pdf不重新打开直接下载:无需使用pdf.js,只需要在返回结果后面拼接 '?response-content-type=application/octet-stream':

 this.service.buildContractPdf(params).subscribe(res => {
      if (res.code == 0) {
        // const newStr = res.data.split('-');
        // console.log(newStr);
        const link = document.createElement("a");
        link.target = "_blank";
        link.setAttribute("href", this.userInfo.domain + res.data + '?response-content-type=application/octet-stream');
        link.style.visibility = "hidden";
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
      }
    });

4、处理数组中某一条特殊数据放置数组的首位或者最好一位:

0:
childList: Array(2)
0:
childList: Array(3)
0: {id: 39, userId: 0, name: '邮费', parentId: 38, level: 3, …}
1: {id: 45, userId: 0, name: '尿素', parentId: 38, level: 3, …}
2: {id: 43, userId: 0, name: '其他', parentId: 38, level: 3, …}
length: 3
[[Prototype]]: Array(0)
createTime: "2022-08-11 11:51:05.0"
icon: "null202208/FgxtwJygChEBRJ5F-5sNxbzLFA4Q.png"
id: 38
level: 2
modifiedTime: "2022-08-11 11:51:05.0"
name: "一级"
parentId: 1
userId: 0
[[Prototype]]: Object
1: {id: 31, userId: 0, name: '其他', parentId: 1, level: 2, …}
length: 2
[[Prototype]]: Array(0)
createTime: "2022-08-09 13:32:19.0"
icon: null
id: 1
level: 1
modifiedTime: "2022-08-09 13:32:46.0"
name: "收入类别"
parentId: 0
userId: 0
[[Prototype]]: Object
1: {id: 2, userId: 0, name: '支出类别', parentId: 0, level: 1, …}


//方法
res.data.forEach(item => {
        //将数据中的其他项放置所在数组中最后一项
        item['childList'].sort((a, b) => b.name == '其他' ? -1 : 0)
        item['childList'].forEach(ite => {
          ite['childList'].sort((a, b) => b.name == '其他' ? -1 : 0)
        });
      });

你可能感兴趣的:(日常踩坑日记)