先上代码classAlbumArtextendsReact.Component{getStyles(){return{width:"100%",height:"auto",display:"block",position:"relative",margin:0,overflow:"hidden"}}errorImg(img){console.log(img);img.src="../../../../../build/assets/img/main_tray.png";img.onerror=null;}render(){varid=this.props.playerId+"AlbumArt",imgId=this.props.playerId+"AlbumArtImg"return(id={id}style={this.getStyles()}>{...this.props}> id={imgId}ref="art"style={{width:"100%",transform:"translateZ(0)"}}src="http://wwww.baoadkaskdoa.asdasd"onError={this.errorImg(this)}/>)}}其中当img加载失败时,我想让他替换成本地的图片,就写了errorImg事件,但是不知道怎么取到img这个标签本身,我现在这么写,取到的this是整个class。问:onError={this.errorImg(this)}如何书写才能取到img标签本身?
梦里花落0921
相关分类