当前位置:网站首页>十二、form表单的提交
十二、form表单的提交
2022-08-02 22:51:00 【Ming-Afresh】
信息填报类项目form表单必不可少
这里我们主要用到两种方式
<form @submit="onSubmit">
<view class="uni-form-item">...</view>
<view class="uni-form-item">...</view>
<button form-type="submit">保存</button>
<view class="uni-form-item">...</view>
<view class="uni-form-item">...</view>
<button @click="onClick">保存</button>
如果两种都加 那是不是同时触发呢?当然不是
@submit和@click也是区分优先级的 如上方法名称举例
onSubmit只能表单上使用,提交表单前会触发,onClick是按钮等控件来使用,用来触发点击事件。在提交表单前,一般都会进行数据验证,可以选择在submit按钮上的onClick中验证,也可以在onSubmit中验证。但是onClick比onSubmit更早的被触发
提交过程
1、用户点击按钮
2、触发onClick事件
3、onClick返回true或未处理onClick
4、触发onSubmit事件
5、onSubmit未处理或返回true
6、提交表单 onSubmit处理函数返回false,onClick函数返回false,都不会引起表单提交
尽可能的只用一种提交方法 写得花里胡哨作用都一样 两种还占用运行没必要
<template>
<view class="content">
<form @submit="onSubmit">
<view class="uni-form-item">
<view class="title">天音波</view>
<view class="input_box"><input type="text" placeholder="请输入" v-model="form.name" maxlength='30' />
</view>
<view class="uni-form-item">
<view class="title">金钟罩</view>
<view class="input_box"><input type="text" placeholder="请输入" v-model="form.name" maxlength='30' />
</view>
<view class="uni-form-item">
<view class="title">神龙摆尾</view>
<view class="input_box"><input type="text" placeholder="请输入" v-model="form.name" maxlength='30' />
</view>
<view>
<button form-type="submit" class="sub_btn clo" :disabled="btnDisabled">保存</button>
</view>
</form>
</view>
</template>
<script>
export default {
data() {
return {
form: {
name: '',
},
btnDisabled:false,
}
},
onLoad() {
},
methods: {
onSubmit(e){
var _this =this;
if(_this.btnDisabled){
uni.showToast({
icon:'none',
title:'请勿重复提交'
})
}
if(_this.form.name==''){
uni.showToast({
icon:'none',
title:'请选择姓名'
})
return false
}
_this.btnDisabled=true
uni.request({
url: 'Where You Going, Baby?',
method: 'POST',
data: {
name:_this.form.name,
...
},
header: {
'content-type': 'application/json'
},
success: res => {
console.log(res.data);
if(res.data==1){
uni.showToast({
icon:'none',
title:'上报成功',
})
setTimeout(()=>{
uni.navigateBack({
delta:0
})
},1000)
};
},
fail: (err) => {
uni.showToast({
icon:'none',
title:err.data.msg,
})
},
});
},
}
}
</script>
边栏推荐
- resubmit 渐进式防重复提交框架简介
- Kubernetes 进阶训练营 网络
- 秒懂网络拓扑中的下一跳地址
- APT level comprehensive free kill with Shell
- Rebound shell principle and implementation
- 厌倦了安装数据库?改用 Docker
- vscode 自定义快捷键——设置eslint
- d实验新异常
- IDO预售代币合约系统开发技术说明及源码分析
- What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?
猜你喜欢

centos7安装mysql5.7步骤(图解版)

脂溶性胆固醇-聚乙二醇-叠氮,Cholesterol-PEG-Azide,CLS-PEG-N3

一个很少见但很有用的SQL功能

No-code development platform form styling steps introductory course

CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物

Test | ali internship 90 days in life: from the perspective of interns, talk about personal growth

Shunted Self-Attention via Multi-Scale Token Aggregation

js基础知识整理之 —— 闭包

Day117.尚医通:生成挂号订单模块

centos7安装mysql8
随机推荐
qt静态编译出现Project ERROR: Library ‘odbc‘ is not defined
2022暑假牛客多校1 (A/G/D/I)
MySQL最大建议行数2000w, 靠谱吗?
基于两级分解和长短时记忆网络的短期风速多步组合预测模型
基于STM32的FLASH读写实验含代码(HAL库)
Strict feedback nonlinear systems based on event trigger preset since the immunity of finite time tracking control
执子手,到永恒
Towards a General Purpose CNN for Long Range Dependencies in ND
【UE5 骨骼动画】全形体IK导致Two Bone IK只能斜着移动,不能平移
Mock工具之Moco使用教程
2022中国眼博会,山东眼健康展,视力矫正仪器展,护眼产品展
PHP实现登录失败三次需要输入验证码需求
基于飞腾平台的嵌入式解决方案案例集 1.0 正式发布!
Jmeter secondary development to realize rsa encryption
IDEA 重复代码的黄色波浪线取消设置
学习基因富集工具DAVID(2)
MDL 内存描述符链表
Token、Redis实现单点登录
resubmit 渐进式防重复提交框架简介
最近公共祖先(LCA)学习笔记 | P3379 【模板】最近公共祖先(LCA)题解