首先在constructor中设置5秒的时间值
constructor (props) {
super(props)
this.state={
seconds: 5,
dlgTipTxt: '5s后关闭页面'
};
}
componentDidMount中添加定时器
componentDidMount () {
let timer = setInterval(() => {
this.setState((preState) =>({
seconds: preState.seconds - 1,
dlgTipTxt: `${preState.seconds - 1}s后自动关闭`,
}),() => {
if(this.state.seconds == 0){
clearInterval(timer);
window.close()
}
});
}, 1000)
}
render中添加判断
render() {
return (
<Result
status="403"
title="403"
subTitle="抱歉你没有权限访问页面"
extra={
<Button>
{this.state.dlgTipTxt}
</Button>
}
/>
)
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-9643.html