首頁  >  文章  >  web前端  >  如何處理vue按鈕多次點擊重複提交數據

如何處理vue按鈕多次點擊重複提交數據

php中世界最好的语言
php中世界最好的语言原創
2018-05-30 14:43:413203瀏覽

這次帶給大家如何處理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
}
})
}
}

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

Angular路由內路由守衛該如何使用

React路由跳轉方法匯總

以上是如何處理vue按鈕多次點擊重複提交數據的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn