验证码,组件

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
	}
}

  

1、路在何方? 路在脚下 2、何去何从? 每个人都在探索,未来的方向在何处。如果说某些方向是世人已经公认的,那么就先按照公认的去走吧(ps:站在巨人的肩膀上看世界会清晰)。 如果说方向,当今世人还不清晰准确。那么就大胆往前走吧,对与错并不重要。心中的方向更加重要。
原文地址:https://www.cnblogs.com/yuanjili666/p/13745889.html