当前位置:网站首页>十二、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>
边栏推荐
- Directing a non-relational database introduction and deployment
- Rebound shell principle and implementation
- 微信小程序实现lot开发09 接入微信登录
- MySQL 用id分库使用name查询
- DownMusic summary record
- threejs dynamically adjust the camera position so that the camera can see the object exactly
- 2022杭电多校第一场(K/L/B/C)
- Cholesterol-PEG-Amine,CLS-PEG-NH2,胆固醇-聚乙二醇-氨基脂两亲性脂质衍生物
- 2022第十一届财经峰会:优炫软件斩获双项大奖
- CIO修炼手册:成功晋升CIO的七个秘诀
猜你喜欢

Technology Sharing | How to do assertion verification for xml format in interface automation testing?

CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物
![[论文总结] 深度学习在农业领域应用论文笔记10](/img/e8/0ba741980495cd81ca30bf269d1111.jpg)
[论文总结] 深度学习在农业领域应用论文笔记10

非关系型数据库MongoDB简介和部署

基于STM32设计的老人防摔倒报警设备(OneNet)

HCIP(17)

ROS2初级知识(9):bag记录过程数据和重放

MySQL 与InnoDB 下的锁做朋友 (四)行锁/记录锁

00 -- jieba分词

CodeTON Round 2 A - D
随机推荐
2022暑假牛客多校1 (A/G/D/I)
The latest real software test interview questions are shared. Are you afraid that you will not be able to enter the big factory after collecting them?
resubmit 渐进式防重复提交框架简介
Week 7 - Distributional Representations
思源笔记 本地存储无使用第三方同步盘,突然打不开文件。
MySQL 用id分库使用name查询
Apache Doris 1.1 特性揭秘:Flink 实时写入如何兼顾高吞吐和低延时
APT级全面免杀拿Shell
聚乙二醇衍生物4-Arm PEG-DSPE,四臂-聚乙二醇-磷脂
DownMusic总结记录
CTF命令执行题目解题思路
如何使用vlookup+excel数组公式 完成逆向查找?
学习基因富集工具DAVID(3)
msys2下载地址
IDEA 重复代码的黄色波浪线取消设置
程序员常说的“左手锟斤拷,右手烫烫烫”是怎么回事?
Towards a General Purpose CNN for Long Range Dependencies in ND
R语言自学 1 - 向量
ssm整合(三)Controller 和 视图层编写
scala 集合通用方法