您可以使用自定义验证规则来验证newId的数据类型是否为数字。例如:

const rules = reactive<FormRules>({
  newsID: [
    { required: true, message: "请输入关联ID", trigger: "blur" },
    { max: 30, message: "限制30位字符", trigger: "blur" },
    {
      validator: (rule, value, callback) => {
        if (typeof value !== "number") {
          callback(new Error("关联ID必须是数字"));
        } else {
          callback();
        }
      },
      trigger: "blur",
    },
  ],
});

这样,当newId的数据类型不为数字时,会显示错误提示信息"关联ID必须是数字"。

const rules = reactiveFormRules newsID required true message 请输入关联ID trigger blur max 30 message 限制30位字符 trigger blur ;要求:验证newId 的数据类型只允许是数字

原文地址: https://www.cveoy.top/t/topic/jbX8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录