本来是想着看看有没有什么方法在input标签里去做限制,目前没找到方法,只有用if去判断
统一给需要的input标签去绑定统一事件
<el-form-item label="代发价格:" prop="model.sku.behalf_price">
<el-input type="number" v-model="form.model.sku.behalf_price" class="max-w460" @input="numberchange"></el-input>
</el-form-item>
然后再方法里统一将需要判断的字段拿去判断,如果要更简洁的方法也欢迎留言
methods:{
numberchange (e) {
if(this.form.model.sku.stock_num<0) this.form.model.sku.stock_num = 1
if(this.form.model.sku.product_weight<0) this.form.model.sku.product_weight = 1
if(this.form.model.sku.start_num<0) this.form.model.sku.start_num = 1
if(this.form.model.sku.wholesale_price<0) this.form.model.sku.wholesale_price = 1
if(this.form.model.sku.behalf_price<0) this.form.model.sku.behalf_price = 1
console.log(e)
}
}