async sendCode() { if (!this.form.mobile) { alert('请输入手机号码'); return; } this.isSending = true; try { await this.axios.post('http://localhost:9998/user/code/',{mobile:this.form.mobile}).then((resp) => { console.log(this.form.mobile); this.isSending = false; let data = resp.data; console.log(data) if (data.data) { this.$message({ showClose: true, message: '发送成功,请输入验证码!', type: 'success' }); } }); } catch (error) { // 添加错误参数 console.log(error); console.log() this.$message({ message: '发送失败', type: 'error' }); } } }这段代码能将mobile传送给后端吗
时间: 2024-02-14 22:20:22 浏览: 32
可以的,这段代码使用axios发送了一个POST请求,请求的URL是http://localhost:9998/user/code/,请求的数据是{mobile:this.form.mobile},其中this.form.mobile表示前端中的手机号码。后端应该可以正确接收到该参数。在请求成功后,控制台会输出手机号码和服务器返回的数据。如果请求失败,控制台会输出错误信息。
相关问题
getUUID() { return new Date().getTime(); }, async onSubmitTap() { if ((!this.ruleForm.caipinUuidNumber)) { this.$utils.msg(`商品编号不能为空`); return } if ((!this.ruleForm.caipinName)) { this.$utils.msg(`商品名称不能为空`); return } if ((!this.ruleForm.caipinPhoto)) { this.$utils.msg(`商品照片不能为空`); return } if ((!this.ruleForm.caipinKucunNumber) && (!this.$validate.isIntNumer(this.ruleForm.caipinKucunNumber)) && this.ruleForm.caipinKucunNumber >0) { this.$utils.msg(`商品库存不能为空,不能小于0 格式为数字`); return } if ((!this.ruleForm.caipinClicknum) && (!this.$validate.isIntNumer(this.ruleForm.caipinClicknum)) && this.ruleForm.caipinClicknum >0) { this.$utils.msg(`点击次数不能为空,不能小于0 格式为数字`); return
这段代码是一个Vue组件中的方法,包含了一个getUUID函数和一个onSubmitTap函数。
getUUID函数返回当前时间的毫秒数,用作一个唯一的ID。
onSubmitTap函数是一个表单提交的事件处理函数,用于验证表单中的各个字段是否合法,如果不合法则给出相应的提示信息。具体验证逻辑如下:
- 如果商品编号为空,则提示“商品编号不能为空”,并退出函数。
- 如果商品名称为空,则提示“商品名称不能为空”,并退出函数。
- 如果商品照片为空,则提示“商品照片不能为空”,并退出函数。
- 如果商品库存为空、不是整数或小于等于0,则提示“商品库存不能为空,不能小于0,格式为数字”,并退出函数。
- 如果商品点击次数为空、不是整数或小于等于0,则提示“点击次数不能为空,不能小于0,格式为数字”,并退出函数。
如果以上所有条件都满足,则表单验证通过,可以进行后续的操作。
let checkResult; if(this.formEntity.ExamType==0){ checkResult = this.checktypetask(this.formEntity.ExamType, this.formEntity.DrillOrgIDarr, this.formEntity.PostId) }else{ checkResult = this.checktypetask(this.formEntity.ExamType, this.formEntity.ByCheckOrgIDs, this.formEntity.PostId) } console.log(checkResult, 'checkResultcheckResultcheckResult') if(!checkResult){ console.log(checkResult, 'checkResultcheckResultcheckResult') return }checkResult返回的是一个promise对象,怎么拿到他的返回值
要获取 `checkResult` 的返回值,可以使用 `async/await` 或者 `.then()` 方法。
使用 `async/await`:
```
async function someFunction() {
let checkResult;
if (this.formEntity.ExamType == 0) {
checkResult = await this.checktypetask(this.formEntity.ExamType, this.formEntity.DrillOrgIDarr, this.formEntity.PostId);
} else {
checkResult = await this.checktypetask(this.formEntity.ExamType, this.formEntity.ByCheckOrgIDs, this.formEntity.PostId);
}
console.log(checkResult, 'checkResultcheckResultcheckResult');
if (!checkResult) {
console.log(checkResult, 'checkResultcheckResultcheckResult');
return;
}
// handle the result here
}
```
使用 `.then()` 方法:
```
function someFunction() {
let checkResult;
if (this.formEntity.ExamType == 0) {
checkResult = this.checktypetask(this.formEntity.ExamType, this.formEntity.DrillOrgIDarr, this.formEntity.PostId);
} else {
checkResult = this.checktypetask(this.formEntity.ExamType, this.formEntity.ByCheckOrgIDs, this.formEntity.PostId);
}
checkResult.then((result) => {
console.log(result, 'checkResultcheckResultcheckResult');
if (!result) {
console.log(result, 'checkResultcheckResultcheckResult');
return;
}
// handle the result here
});
}
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)