[eslint] 遇到的一些問題及解決方法
阿新 • • 發佈:2018-12-27
如覺得不對,請見諒,本文謹記錄本人專案過程中遇到的[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}');
}