修改bug遇到的吐血集锦

1、分页

先把分页考虑进去, 页码清零必做(初始查询页码清零,修改查询条件页码清零)

2、时间日期为阶段型

对开始时间和结束时间要做限制,对时间未选充分需要做限制(比如只选开始时间和只选结束时间情况)

3、省市区联动

重新选择要对二三级信息清零

4、下拉框

下拉框都要做全部选项(不然切换不回去),且都要做初始选项

5、commonJs规范

require+module.exports import +export default

react 报错

"TypeError: Cannot assign to read only property 'exports' of object '#<Object>'"

找了半天,终于找到原因。    

You can mix require and export. You can‘t mix import and module.exports.  

提醒自己,以后一定要配对使用require和module.exports以及import和export default。

而且貌似只有mac报错!   

原因:node的module遵循CommonJs规范,使用的是Common的module.export和自己定义的require命令,
但是:es6的module没有采用CommonJs,定义了模块的export和import命令。

6、数组删除

循环数组并删除某项数组不能正向遍历

let arr = [1,2,2,2,2,3,4];
 arr.forEach((v,i)=>{
 	if(v===2){
        arr.splice(i,1);
        }
  }) 
  console.log(arr); //输出[1,2,2,3,4] 

可以发现没有完全删除2,因为正向遍历数组索引改变,导致会有一个紧随2的值未被删除。

解决办法: 反向遍历

let arr = [1,2,2,2,2,3,4];
for(let i = arr.length;i > 0;i--){
	if(arr[i] === 2){
        arr.splice(i,1);
    }
}
console.log(arr); //输出[1,3,4]
7、if(condition)

判断成立与否的condition条件值不一定是布尔值,js会自动调用Boolean()转换函数将condition结果转换。

Boolean() 函数:如果对象无初始值或其值为0 ,-0,null,“‘,false,undefined,NaN,那么结果为false,否则为true。

思考:Boolean( “false”)

let boolean = new Boolean(false); 
if(boolean){
	console.log("Js is amazing");
}

if(boolean == true){
	console.log("hhhh");
}
第一个if 隐士转换调用Boolean(boolean),由于boolean是对象,所以值为true
第二个if == 运算符 对象会调用valueOf(boolean)方法,boolean值为false,所以值为false
8、如何判断json对象下的某一个属性值是否存在

同上面第七点:所以不能直接判断 if(obj.type)

假如type值为0,if语句依然是false

三种方法:

1、obj.hasOwnProperty(prop)

2、in关键字 if(prop in obj)

3、!== undefined if(obj.name !== undefined)

OK 完美解决