今天写vue的时候发现一个很灵异的问题。
let mark;
if(this.AuthState===true){
mark=0;
}else{
mark=1;
}
let data = {
creator: this.userInfo.employeeCode,
isLimited:mark,
};
console.log(data);
DisplacementQueryDataApi(data).then((res) => {
if (res.data && res.data[0]) {
this.dataTable = res.data;
this.dataTable.map((item) => {
let target = {
id: '',
text: '',
};
if(item['isCommon']==='N'){
target.id = item['id'].toString();
target.text =
item['minDisplacement'] + 'L~' + item['maxDisplacement'] + 'L';
this.PLList.push(target);
}else if(item['isCommon']==='Y'){
target.id = item['id'].toString();
target.text =
item['minDisplacement'] + 'L~' + item['maxDisplacement'] + 'L(公有)';
this.PLList.push(target);
this.CommonList.push(item);
}
});
}
});
在这段代码里,先判断this.AuthState
是false
还是true
,并分别吧mark设置为0或者1并赋值给data,然后使用data作为header向发送一个请求,但是发现一个问题,当mark为0的时候,在发送请求的前一秒data.isLimited
都是0,发送请求后header就自动变为null。
这导致请求发生错误。
然后问了别人,说是发请求的时候vue会自动把0的数字换成null……
最后的办法是连后端一起改掉,这个0改为用2……
然后就能正常发送报文了。