vue.js - 验证为真后如何在vue js中隐藏错误消息?
问题描述
实际上我的问题是我正在通过 v-on:input 检查特定值何时有效。如果该值无效,我会得到“无效数据”的响应,并且显示相同。但是,当值变为有效时,“无效数据”并没有隐藏。我怎么能这样做。
我的代码是
methods: {
checkLimit: function () {
var vm = this;
data = {};
if (this.no != '') data['no'] = this.no;
$.ajax({
url: "doc/checkNumber",
method: "POST",
data: data,
dataType: "JSON",
success: function (e) {
if (e.status == true) {
}
else{
console.log(e.msg);
vm.error = e.msg;
}
},
});
},
}
因此,如果状态为假,我将显示为
<input type="text" class="form-control" v-model="orno" required=""
v-on:input="checkLimit" maxlength="3"><p>{{error}}</p>
但是当 Status 为 true 时,错误消息仍然存在。如何根据更改进行更新?
解决方案
当为真时,您应该将 设置error
为。像这样''
e.status
success: function (e) {
if (e.status == true) {
vm.error = '';
} else {
console.log(e.msg);
vm.error = e.msg;
}
},
推荐阅读
- python - 用户条目作为熊猫中的列名
- stored-functions - 如何刷新 ADS 存储过程中的缓冲区?
- mysql - Bitnami Wordpress phpmyadmin 无法连接到 mysql
- html - Internet Explorer 11,如何设置只读样式?
- php - 如何从 API 结果中选择特定值
- python - 简单来说super()的用例是什么
- ios - 对 AudioKit FM 振荡器参数执行基本算术运算:插值和时间转换
- ssl - Kubernetes 添加域名和 SSL
- javascript - Angular:覆盖嵌套组件的scss样式
- java - Java 时区数据库与 IANA 数据