风华正茂、时光流逝、真爱时光、努力创建辉煌。

验证码,组件

 

 

 

import React, { Component } from 'react';
import NetCommon from '@/net/common';

export default class extends Component {
	state = {
		captcha: '',
		loading: false
	}
	getSrc = () => {
		if (this.state.loading) return;
		this.state.loading = true;	
		NetCommon.getCaptcha().then((res) => {
			this.state.loading = false;
			this.setState({captcha: res.data.captcha})
		}).catch(() => {
			this.state.loading = false;
		});
	}
	componentDidMount() {
		this.getSrc();
	}
	render() {
		const { captcha } = this.state;
		return captcha ? <img title="点击刷新验证码"  {...this.props} src={captcha} onClick={this.getSrc} /> : null
	}
}

  

 

posted @ 2020-09-28 17:25  野马,程序源改造新Bug  阅读(185)  评论(0编辑  收藏  举报