sách gpt4 ai đã đi

reactjs - ReactJS 如何在用户不活动时自动注销?

In lại 作者:行者123 更新时间:2023-12-03 13:25:57 32 4
mua khóa gpt4 Nike

我需要知道 REACT JS 或 HTML5 中是否有任何 API 可以提供用户不活动时自动注销的功能。我的代码如下,我不知道出了什么问题,它给了我错误 startTimer 未定义和不必要的绑定(bind)。请告诉我哪里出错了

import React từ 'react';
import ReactDOM from 'react-dom';
import './App.css';

class Toogle extends React.Component {
constructor(props) {
super(props);
//step 1
this.handleClick = this.handleClick.bind(this);
this.startTimer=this.startTimer.bind(this)
}

handleClick() {
console.log('Button is clicked');

// clearTimeout(timeoutTimer);
startTimer() {
var timeoutTimer = setTimeout(function() {
window.location.href = '#/security/logout';
}.bind(this), 1000);
}
}

render() {
trở lại (

Move the cursor over me

);
}
}

ReactDOM.render(
,
document.getElementById('root')
);

1 Câu trả lời

接受的答案可能适合您,但导航路线之间的时间并不是真正的“非事件”时间。

react-idle可以做到这一点,阅读文档,您就可以按照应该的方式进行操作。

关于reactjs - ReactJS 如何在用户不活动时自动注销?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40888776/

32 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com