您好,欢迎访问一九零五行业门户网

vue按钮多次点击重复提交数据如何处理

这次给大家带来vue按钮多次点击重复提交数据如何处理,处理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>
这里我们通过控制isdisable 来设置 disabled来控制按钮的点击和不可点击。 默认isdisable:的值为 false,按钮可以点击。 当我们点击这个按钮的时候,首先将按钮的绑定isdisable设置为true,1秒后立马将其置为false。 所以用户只能有一秒的时间去操作这个按钮。
下面给大家补充一个实例代码
vue中button 多次点击重复提交的实例代码
sendcomment () { this.disabled = true if (this.text == ''){ this.$message({ type:'error', message:'输入内容不能为空', }) this.disabled = false }else{ this.$post('/xx/xx/idlegoodscomment',{ goods_id:this.$route.params.id, content:this.text, user_id:window.uid, type:1 }).then((res) => { if(res){ this.getdetail() settimeout(()=>{ this.disabled=false this.getcommentlist() this.text = ''} ,2000) this.disabled = true } }) } }
实现原理:通过计时器讲button属性更改,点击完之后讲button属性设置为disable
vue绑定button的disable属性为:disabled:'变量名'
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
js实现一个简易的计算器步骤详解
react路由管理react router使用步骤详解
以上就是vue按钮多次点击重复提交数据如何处理的详细内容。
其它类似信息

推荐信息