react 上传头像

import React from 'react';
import axios from 'axios'
export default class My extends React.Component{
                     constructor(props){
                           super(props);
                           this.state={
                                imgurl:''
                           }
                     }
                     
                     componentDidMount(){
                           
                     }
                     load(){
                           this.refs.loading.style.display="block"
                           let file=this.refs.file
                           console.log(file.files[0])
                           let forData=new FormData
                           forData.append('headfile',file.files[0])
                           var url="http://vueshop.glbuys.com/api/user/myinfo/formdatahead?token=1ec949a15fb709370f"
                           axios({
                                method:"post",
                                url:url,
                                data:forData
                           }).then(res=>{
                           this.refs.loading.style.display="none"
                                
                                console.log(res.data)
                                if(res.data.code==200)
                                {
                                     let temp="//vueshop.glbuys.com/userfiles/head/"
                                     this.setState({
                                           imgurl:temp+res.data.data.msbox
                                     })
                                }
                           })
                     }
                     
                     
                     
                     //jsx
                     render(){
                           return(
                                
上传中....
) } }

你可能感兴趣的:(前端)