vue 按钮多次点击重复提交数据

这个其实是一个很细节的问题。 如果我们操作一个按钮,然后在按钮点击的时候绑定事件。 
事件分为两种情况:

  • 第一种: 不操作数据型
  • 第二种: 操作数据型
<template>
  <button @click="submit()" :disabled="isDisable">点击</button>
</template>

<script>
  export default {
    name: 'TestButton',
    data: function () {
      return {
        isDisable: false
      }
    },
    methods: {
      submit() {
        this.isDisable = true
        setTimeout(() => {
          this.isDisable = false
        }, 1000)
      }
    },
  }
</script>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

这里我们通过控制isDisable 来设置 disabled来控制按钮的点击和不可点击。 默认isDisable:的值为 false,按钮可以点击。 当我们点击这个按钮的时候,首先将按钮的绑定isDisable设置为true,1秒后立马将其置为false。 所以用户只能有一秒的时间去操作这个按钮。

猜你喜欢

转载自blog.csdn.net/sinat_17775997/article/details/80175783