首页 > 解决方案 > 验证为真后如何在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 时,错误消息仍然存在。如何根据更改进行更新?

标签: vue.jsvuejs2vue-component

解决方案


当为真时,您应该将 设置error为。像这样''e.status

 success: function (e) {
    if (e.status == true) {
        vm.error = '';
    } else {
       console.log(e.msg);
        vm.error = e.msg;
    }
 },

推荐阅读