限制用户接口访问次数
前端控制
前端控制用户接口的访问次数可以使用Local Storage实现
案例:限制用户一小时内只能提交10次请求
handleSubmit() {
if (!this.canSubmit) return;
const nowTime = new Date().getTime();
const data = Object.assign({ advisoryTime: nowTime }, this.redisterData);
data.classificationId = this.$route.query.classificationId;
const submitFrequency = getLocalStorage('solutionRegisterFrequency');
const submitTime = getLocalStorage('solutionRegisterTime');
if (!submitTime || nowTime - submitTime > 3600000) {
solutionRegister(data).then((res) => {
if (res.code === '200') {
setLocalStorage('solutionRegisterFrequency', 1);
setLocalStorage('solutionRegisterTime', nowTime);
this.dialogMsg = this.successMsg;
this.clearSubmitData();
}