之前写过一个发送短信的功能
Element中使用<el-radio-button>实现短信平台功能, 通过点击不同的按钮,向不同的人发送消息_newbaby123的博客-优快云博客
上次写的不太完善,忘记添加控制判断,今天来写一写
if(this.msg.trim() == '') {
this.$message.warning('发送内容不可为空')
return
}
这样如果输入框内容为空,就无法发送
完善一下onSubmit的代码(sendMsg是后端接口)
onSubmit() {
if(this.msg.trim() == '') {
this.$message.warning('发送内容不可为空')
return
}
this.$confirm("确定发送该信息吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
this.activated = false;
sendMsg({ msg: this.msg, type: this.type })
.then(res => {
if (res.data.code === 0) {
console.log(res);
this.$message.success(res.data.data);
this.activated = true;
} else {
this.$message.error(res.data.msg);
this.activated = true;
}
})
.catch(res => {
this.activated = true;
});
})
.catch(() => {
this.$message.error("已取消发送");
});
}