<template>
<el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px">
<el-form-item label="优惠券金额" prop="discount_amount">
<el-input
v-model="ruleForm.discount_amount"
@input="handleInput"
placeholder="请输入正整数"
></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm">提交</el-button>
</el-form-item>
</el-form>
</template>
<script>
export default {
data() {
return {
ruleForm: {
discount_amount: "",
},
rules: {
discount_amount: [
{ required: true, message: "请输入优惠券金额", trigger: "blur" },
],
},
};
},
methods: {
handleInput() {
this.ruleForm.discount_amount = this.ruleForm.discount_amount
.replace(/\D/g, "") // 只允许输入数字
.replace(/^0+/, ""); // 禁止输入前导0
},
submitForm() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
alert("提交成功!");
} else {
console.log("表单验证失败");
return false;
}
});
},
},
};
</script>
11-03
3156
3156
05-13
930
930
04-02
1011
1011
04-08
4328
4328

被折叠的 条评论
为什么被折叠?



