vue工程 el-button添加全局防抖设置

一、main.js中

给按钮加上一个全局指令 noMoreClick 来限制在一定的时间内控件为 disabled不让再次点击

 
//在main.js中
// 提交以后禁用按钮一段时间,防止重复提交
import Vue from 'vue'
Vue.directive('noMoreClick', {
  inserted(el, binding) {
    el.addEventListener('click', e => {
      el.classList.add('is-disabled')
      el.disabled = true
      setTimeout(() => {
        el.disabled = false
        el.classList.remove('is-disabled')
      }, 2000)//我这里设置的是2000毫秒也就是2秒
    })
  }
})

二、vue页面中el-button控件

el-button使用该全局指令即可。

<el-button v-no-more-click type="primary" >保存</el-button>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
el-buttonElement UI中的一个组件,用于创建按钮。它有以下几个属性: 1. type:按钮类型,可选值为primary、success、warning、danger和info,默认值为default。 2. size:按钮尺寸,可选值为medium、small和mini,默认值为medium。 3. icon:按钮图标,可以使用Element UI中的图标或自定义图标。 4. disabled:禁用按钮,可选值为true或false,默认值为false。 5. loading:加载状态,可选值为true或false,默认值为false。 6. plain:朴素按钮,可选值为true或false,默认值为false。 7. round:圆形按钮,可选值为true或false,默认值为false。 8. circle:圆角按钮,可选值为true或false,默认值为false。 9. autofocus:自动获取焦点,可选值为true或false,默认值为false。 使用示例: ```html <template> <div> <el-button>默认按钮</el-button> <el-button type="primary">主要按钮</el-button> <el-button type="success">成功按钮</el-button> <el-button type="warning">警告按钮</el-button> <el-button type="danger">危险按钮</el-button> <el-button type="info">信息按钮</el-button> <el-button size="medium">中等按钮</el-button> <el-button size="small">小按钮</el-button> <el-button size="mini">迷你按钮</el-button> <el-button icon="el-icon-search">搜索按钮</el-button> <el-button disabled>禁用按钮</el-button> <el-button loading>加载按钮</el-button> <el-button plain>朴素按钮</el-button> <el-button round>圆形按钮</el-button> <el-button circle>圆角按钮</el-button> <el-button autofocus>自动获取焦点按钮</el-button> </div> </template> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值