博客
关于我
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 子进程 Popen:为什么会出现“ls *.txt“?不行?
查看>>
Python 子进程参数
查看>>
python 字典 key 和value 互换
查看>>
Python 字典 vs If 语句速度
查看>>
python 字典sorted自定义排序,按照key or value排序
查看>>
python 字典和列表区别_元组列表和字典的主要区别是什么?
查看>>
python 字符串中特定字符替换,截取
查看>>
Python 字符串总结
查看>>
python 字符串显示中文_Python字符串开头的b"、u"、r"与中文乱码
查看>>
Python 字符串的几种拼装方式
查看>>
python 存入数据库bigint_python基础_MySQL的bigint类型
查看>>
python 学习 面向对象编程
查看>>
Python 学习小结
查看>>
Python 学习日记第三篇 -- 字典
查看>>
Python 学习笔记(一)Data type
查看>>
python 安装 easy_install 和 pip 流程
查看>>
python 安装echarts
查看>>
python 安装opencv及问题解决
查看>>
Python 安装程序:“写入文件 C:\Python27\pythonw.exe 时出错“
查看>>
Python 安装避坑指南:从入门到进阶
查看>>