当前位置:   article > 正文

vue form表单循坏并校验_vue form list表单

vue form list表单

 

 

  1. <template>
  2. <div>
  3. <el-form :model="ruleForm" ref="ruleForm" label-width="100px">
  4. <el-form-item label="分类" required>
  5. <el-row :gutter="20" v-for="(item,index) in ruleForm.list" :key="index">
  6. <el-col :span="6">
  7. <el-form-item :prop="'list.'+index+'.name'" :rules="rules.name">
  8. <el-input type="text" v-model="item.name"></el-input>
  9. </el-form-item>
  10. </el-col>
  11. <el-col :span="6">
  12. <el-form-item :prop="'list.'+index+'.num'" :rules="rules.num">
  13. <el-input type="text" v-model="item.num"></el-input>
  14. </el-form-item>
  15. </el-col>
  16. </el-row>
  17. </el-form-item>
  18. </el-form>
  19. <el-button type="primary" @click="btn('ruleForm')">提交</el-button>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. data(){
  25. return{
  26. ruleForm:{
  27. list:[
  28. {
  29. name:'',
  30. num:''
  31. },
  32. {
  33. name:'',
  34. num:''
  35. }
  36. ],
  37. },
  38. rules: {
  39. name:[{required: true, message: "请选择分类", trigger: "blur"}],
  40. num:[{required: true, message: "请选择分类1", trigger: "blur"}],
  41. },
  42. }
  43. },
  44. methods:{
  45. btn(formName){
  46. this.$refs[formName].validate((valid) => {
  47. if (valid) {
  48. alert('submit!');
  49. } else {
  50. console.log('error submit!!');
  51. return false;
  52. }
  53. });
  54. }
  55. }
  56. }
  57. </script>
  58. <style>
  59. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/69905
推荐阅读
相关标签
  

闽ICP备14008679号