admin管理员组文章数量:1130349
如觉得不对,请见谅,本文谨记录本人项目过程中遇到的[eslint] 问题及一些处理方式。
一、[eslint] Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.
如下:
delBgImage =(id)=>{
const url = `${chatBgChangeUrl}?chat_bg_id=${id}`;
fetch(url,{
method: 'DELETE',
headers:{
'Authorization': Token
},
}).then(res =>{
return res.json();
}).then((data)=>{
if(parseInt(data.errorcode,10) === 0){
this.loadListData();
this.upSuccess();
}else {
this.delError();
}
}
)
}
解决:
putBgImage =async(id)=>{
try{
const url = `${chatBgChangeUrl}?chat_bg_status=1&chat_bg_id=${id}`;
fetch(url,{
method: 'PUT',
headers:{
'Authorization': Token
},
}).then(res =>(
res.json()
)).then((data)=>{
debugger;
if(parseInt(data.errorcode,10) === 0){
this.loadListData();
this.upSuccess();
}else {
this.putError();
}
})
}catch(err){
this.putError();
}
}
二、[eslint] img elements must have an alt prop, either with meaningful text, or an empty string for decorative images. [jsx-a11y/alt-text]
如下:
<img src={this.state.imgUrl} />
解决:
<img src={this.state.imgUrl} alt="" />
三、[eslint] Unexpected string concatenation.
const url =hallGbsChangeUrl+'?bg_id='+id;
解决:
const url = `${hallGbsChangeUrl}?bg_id=${id}`;
hallGbsChangeUrl、id为变量
四、[eslint] Parsing error: await is a reserved word
loadListData = () => {
const response = await fetch(hallVideoRequestUrl,{
method:'GET',
headers:{
'Authorization':Token
}
});
....
};
解决:
loadListData = async () => {
const response = await fetch(hallVideoRequestUrl,{
method:'GET',
headers:{
'Authorization':Token
}
});
....
};
附:less 使用
1、引用文件:@import '~antd/lib/style/themes/default.less';
2、引用图片:@bgRaceHorse: '../../assets/icon-gameEnd.png';
.container{
margin: 0 auto;
height: 100%;
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
background: url('@{bgRaceHorse}');
}
如觉得不对,请见谅,本文谨记录本人项目过程中遇到的[eslint] 问题及一些处理方式。
一、[eslint] Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.
如下:
delBgImage =(id)=>{
const url = `${chatBgChangeUrl}?chat_bg_id=${id}`;
fetch(url,{
method: 'DELETE',
headers:{
'Authorization': Token
},
}).then(res =>{
return res.json();
}).then((data)=>{
if(parseInt(data.errorcode,10) === 0){
this.loadListData();
this.upSuccess();
}else {
this.delError();
}
}
)
}
解决:
putBgImage =async(id)=>{
try{
const url = `${chatBgChangeUrl}?chat_bg_status=1&chat_bg_id=${id}`;
fetch(url,{
method: 'PUT',
headers:{
'Authorization': Token
},
}).then(res =>(
res.json()
)).then((data)=>{
debugger;
if(parseInt(data.errorcode,10) === 0){
this.loadListData();
this.upSuccess();
}else {
this.putError();
}
})
}catch(err){
this.putError();
}
}
二、[eslint] img elements must have an alt prop, either with meaningful text, or an empty string for decorative images. [jsx-a11y/alt-text]
如下:
<img src={this.state.imgUrl} />
解决:
<img src={this.state.imgUrl} alt="" />
三、[eslint] Unexpected string concatenation.
const url =hallGbsChangeUrl+'?bg_id='+id;
解决:
const url = `${hallGbsChangeUrl}?bg_id=${id}`;
hallGbsChangeUrl、id为变量
四、[eslint] Parsing error: await is a reserved word
loadListData = () => {
const response = await fetch(hallVideoRequestUrl,{
method:'GET',
headers:{
'Authorization':Token
}
});
....
};
解决:
loadListData = async () => {
const response = await fetch(hallVideoRequestUrl,{
method:'GET',
headers:{
'Authorization':Token
}
});
....
};
附:less 使用
1、引用文件:@import '~antd/lib/style/themes/default.less';
2、引用图片:@bgRaceHorse: '../../assets/icon-gameEnd.png';
.container{
margin: 0 auto;
height: 100%;
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
background: url('@{bgRaceHorse}');
}
版权声明:本文标题:[eslint] 遇到的一些问题及解决方法 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1754580962a2704015.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论