from 表单验证:
1、数组表单验证:
data() {
var validateArr = (rule, value, callback) => { // 申明变量validator验证
let res = value.length > 0;
value.forEach((val, index, arr) => {
if (!val && val.length == 0) {
res = false;
}
});
if (!res) {
callback(new Error(rule.message));
} else {
callback();
}
};
return {
rules: {
name: [{ required: true, message: "请输入商品名称", trigger: "blur" }],
ptbhs_supply_price: [
{
required: true,
validator: validateArr,
trigger: "blur",
message: "请输入供货价(不含税)"
}
// { required: true, message: "请输入供货价(不含税)", trigger: "blur" }
],
}
}
}
网友评论