博客
关于我
Vue 前端框架中限制用户短时间内多次点击同一按钮的方法(例如:登录、注册)
阅读量:432 次
发布时间:2019-03-06

本文共 564 字,大约阅读时间需要 1 分钟。

在项目目录中创建一个名为 controlClickState.js 的文件,并在其中添加以下内容:

// controlClickState.js 文件export default {  install(Vue) {    // 禁止短时间内重复点击    Vue.directive('preventClick', {      inserted(button, bind) {        button.addEventListener('click', () => {          if (!button.disabled) {            button.disabled = true;            setTimeout(() => {              button.disabled = false;            }, 6000);          }        });      }    });  }};

在项目的主入口文件 main.js 中引入上述文件:

import preventClick from '../static/js/controlClickState';Vue.use(preventClick);

在需要限制点击频率的组件中使用:

转载地址:http://iknuz.baihongyu.com/

你可能感兴趣的文章
Python 安装程序:“写入文件 C:\Python27\pythonw.exe 时出错“
查看>>
Python 安装避坑指南:从入门到进阶
查看>>
Python 安装配置详解
查看>>
python 实现儿童算术游戏
查看>>
python 实现字符串转整型
查看>>
Python 实现定时任务的八种方案!
查看>>
python 实现将RGBA 转换为RGB
查看>>
python字符串与url编码的转换
查看>>
Python 实现自动化测试 dubbo 协议接口
查看>>
python编程基础之十六
查看>>
python字符串input输入_Python input()函数:获取用户输入的字符串
查看>>
python 对json数据读取及保存与读取,对dump,dumps,load,loads的理解
查看>>
Python 对mysql数据库的操作
查看>>
Python 对象数据库列表
查看>>