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
}
}
原文:https://www.cnblogs.com/yuanjili666/p/13745889.html