<el-form :model="ruleForm" :rules="rules" ref="ruleForm"> <el-form-item label="活动名称" prop="path"> <el-input v-model="ruleForm.path" placeholder="请输入路径"> data() { const checkPath = (rule, value, callback) => { this.ruleForm.path = value.replace(/[\u4E00-\u9FA5]/g, ""); // 一定要执行回调函数 // 否则不起效果 callback(); }; return { ruleForm: { path: "" }, rules: { path: [ { required: true, message: "路径不能为空", trigger: "blur" }, { validator: checkPath, trigger: "change" } ] } }; }, methods: { submitForm() { this.$refs["ruleForm"].validate((valid) => { console.log(valid); }); } } }
vue+element的form表单实现禁止输入汉字(中文),即使输入也替换为空字符串、路径、链接、地址
关注
打赏