做项目时经常遇到表单重复提交的问题 小编带来这一种有效的防止重复提交本人测试有效

上代码:

<form @submit="examine">

<button form-type="submit"  >提交</button>

</from>

examine(e){
              if(this.isCommitted==false){
                  this.isCommitted=true;

               uni.request({
                    url:url+'/CompanyController/addCompany',
                    method:'POST',
                    header:{
                    'Content-type':'application/x-www-form-urlencoded'
                    },
                    data:params,
                    dataType:'json',
                    success:function(res){

                         this.isCommitted=false;//后台请求成功了之后重新赋值false 让表单再次可提交

                    }

                 })
                  console.log("正常提交")
              }else{
                  console.log("不能重复提交")
                  return fasle;
              }
    
            }

到这里基本结束了 后面持续更新使用token令牌机制防止表单重复提交

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐