react头像上传方法

                  
{(123);this.informationList(e)}} id="txsc" /> 点击修改头像
//上传头像图片需转化为base64位
informationList= async(e)=>{ //base64
         //const { dispatch } = this.props;
        //const _this = this;
        var reader = new FileReader();
        reader.readAsDataURL(e.target.files[0]);
        Toast.loading("正在上传头像", 0);
        reader.onloadend = async (e) => {
            const params ={
                headimg:reader.result,
                type:1
            }
            const result = await home.xgheader(params);
            Toast.hide()
            if(result.code == 1){
                home.Usercenter({}).then((result) => {
                    if (result.code === 1) {
                        this.setState({
                            data: result.data
                        })
                    }
                })
                Toast.info('上传成功')
            }else{
                Toast.info('上传失败,请重新上传',1.5)
            }
        }
    }
            

你可能感兴趣的:(javascript,React)