vue中使用elm表单的自定义校验规则

  data() {
    var checkAge = (rule, value, callback) => {
      // console.log(value, "输入的");
      // console.log(this.da, "最大的");
      // console.log(this.xiao, "最小的");
      let value1 = Number(value);
      let xiao1 = Number(this.xiao);
      let da1 = Number(this.da);
      if (value1 > da1 || value1 < xiao1) {
        return callback(new Error("请输入价格区间内的金额"));
      } else {
        callback();
      }
    };
    return {
      xiao: "",
      da: "",
      rules: {
        price: [
          {
            validator: checkAge,
            trigger: "blur"
          }
        ]
      }
    };
  },



   /* 保存编辑 */
    save(form) {
      this.$refs[form].validate(valid => {
        if (valid) {
          this.loading = true;
          let info = {
            appointment_record_id: this.form.id,
            type: 1,
            from: this.form.from,
            order_id: this.form.order_id,
            price: this.form.price
          };
          this.$http
            .post("admin-api/member-order/add", info)
            .then(res => {
              this.loading = false;
              console.log(res);
              if (res.data.status == 1) {
                this.$message({ type: "success", message: "成功" });
                this.form = {
                  type: 1,
                  from: 1
                };
                this.aaaainfo = "";
                this.updateVisible(false);
                this.$emit("done");
              } else {
                this.$message.error(res.data.error);
              }
            })
            .catch(e => {
              this.loading = false;
              this.$message.error(e.message);
            });
        } else {
          return false;
        }
      });
    },
posted @   喜欢Tb  阅读(9)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示