赞
踩
第一步:引入element-ui库,在对应的组件中使用,这一步不用多说。
第二步:配置要用到的表单验证规则,用:rules绑定即可,右边的函数名对应在data中书写的名字,并且给需要验证的那一项(el-form-item)写上对应的字段名,比如这里要校验age字段,就是prop="age"。上代码:
- <el-form :inline="true" :rules="rules" :model="form" ref="form">
- <el-form-item
- label="年龄:"
- label-width="100px"
- prop="age"
- >
- <el-input
- class="el-form-position"
- v-model="form.age"
- oninput="value=value.replace(/[^\d.]/g,'')"
- placeholder="年龄"
- ></el-input>
- </el-form-item>
- <el-form-item class="btn">
- //绑定点击事件,方法中传入的是对应的表单名字(就是第一行ref="form"等式右边的)
- <el-button @click="canc

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。