【工作小tip】uniapp手机号表单校验、请求数据报405

23 篇文章 0 订阅
7 篇文章 0 订阅

uniapp手机号表单校验

<view class="main">
			<u-action-sheet :list="sexlist" v-model="sexShow" @click="actionSheetCallback"></u-action-sheet>
			<u-form :model="form" class="common-form" ref="uForm" :error-type="['border-bottom', 'border', 'toast']"
				label-width="180">
				<view class="w-title">基础信息</view>

				<view class="form-item">
					<u-form-item required label="姓名" prop="name">
						<u-input v-model="form.name" placeholder="请输入姓名" />
					</u-form-item>
					<u-form-item label="性别" prop="sex">
						<view class="full-w">
							<u-input placeholder="请选择性别" v-model="form.sexlabel" type="select"
								@click="sexShow = true" />
						</view>
					</u-form-item>
					<u-form-item required label="手机号码" prop="phone">
						<u-input v-model="form.phone" placeholder="请输入联系电话" type="number" maxlength="11" />
					</u-form-item>
					<u-form-item label="职务" prop="job">
						<u-input v-model="form.job" maxlength="20" placeholder="请输入职务" />
					</u-form-item>
				</view>
				<view class="w-title">备注</view>
				<view class="form-item">
					<u-form-item label="备注" label-position="top" :border-bottom="false" prop="remark">
						<view class="full-w">
							<u-input maxlength="50" v-model="form.remark" class="common-textarea" type="textarea"
								:border="false" :height="300" />
						</view>
					</u-form-item>
				</view>
			</u-form>
		</view>

		<view class="common-footer">
			<view class="text-c mg-b-15 tips">
				<u-checkbox icon-size="24" size="28" label-size="28" v-model="form.isDefault">设为默认联系人</u-checkbox>
			</view>
			<u-button @click="onSubmit" :loading="btnLoading" v-bind="$baseProps.button" size="default" class="full-w">
				确定</u-button>
		</view>
onSubmit() {
      this.$refs.uForm.validate(async (valid) => {
        if (valid) {
          this.btnLoading = true;

          try {
            let check = await ApiContactCheck({
              name: this.form.name,
              phone: this.form.phone,
              id: this.form.enterpriseId,
              contactsId: this.form.id || "",
            });
			if (!/^1[3456789]\d{9}$/.test(this.form.phone)) {
			  throw new Error("请输入正确的手机号");
			}
            if (!check.data.data) {
              throw new Error("姓名或手机号重复");
            }
			
            const Api = this.form.id ? ApiUpdateContacts : ApiAddContacts;
            Api({
              ...this.form,
              isDefault: this.form.isDefault ? "1" : "0",
            })
              .then((res) => {
                uni.navigateBack()
                // this.$flyrise.toast(res.data.msg)
              })
              .finally((_) => {
                this.btnLoading = false;
              });
          } catch (error) {
            this.btnLoading = false;
            this.$refs.uTips.show({
              title: error,
              type: "error",
            });
          }
        }
      });
    },

请求数据报405

debugger定位到对应函数

函数对应到固定接口

看请求预览

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1SZ2I7SS-1658761647499)(img/image-20220725161401466.png)]

message: “Request method ‘GET’ not supported”

不能用get,要用post,改成post就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值