zoukankan      html  css  js  c++  java
  • element ui 表格实现input验证

    <template>
      <div>
        <el-form :model="forms" ref="forms" :rules="rules">
          <el-table :data="forms.voList">
            <el-table-column
            label="商品名称">
              <template slot-scope="scope">
                  <el-input v-model="scope.row.goodsName"></el-input>
              </template>
            </el-table-column>
    
            <el-table-column
              label="商品编码">
              <template slot-scope="scope">
                  <el-input v-model="scope.row.goodsCode"></el-input>
              </template>
            </el-table-column>
    
            <el-table-column
              label="价格">
              <template slot-scope="scope">
                <el-form-item :prop="'voList.'+scope.$index+'.unitPrice'" :rules="rules.unitPrice">
                  <el-input v-model="scope.row.unitPrice"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
    
            <el-table-column
              label="数量">
              <template slot-scope="scope">
                  <el-input v-model="scope.row.num"></el-input>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
        <el-button type="primary" @click="save">保存</el-button>
      </div>
    </template>
    
    <script>
    export default {
      name: "table",
      data(){
        return {
          forms:{
            id:1,
            documentNo:null,
            buyerName:"服务技术",
            buyerDp:"42118XXXXXXXXXX72X",
            buyerBankAccount:"招商银行4890284",
            buyerAddressPhone:"深圳市宝安区110112",
            buyerEmail:null,
            buyerPhone:null,
            buyerType:"01",
            remarks:"这是备注",
            total:350.9,
            voList:[
              {
                goodsName:"黄金",
                goodsCode:"44021940",
                specification:null,
                unit:"克",
                num:1,
                unitPrice:291.37,
                taxRate:0.17,
                taxAmount:49.53,
                favouredPolicy:"0",
                zeroTaxRate:"",
                hsbz:"1"
              },
              {
                goodsName:"花生",
                goodsCode:"4574511",
                specification:null,
                unit:"斤",
                num:1,
                unitPrice:8.55,
                taxRate:0.17,
                taxAmount:1.45,
                favouredPolicy:"0",
                zeroTaxRate:"",
                hsbz:"1"
              }
            ]
          },
          rules:{
            num:[{required:true,message:'数量不能为空',trigger:'blur'}],
            unitPrice:[{required:true,message:'单价不能为空',trigger:'blur'}]
          }
        }
      },
      methods:{
        save(){
          this.$refs['forms'].validate((valid)=>{
            if(valid){
              console.log(1)
            }
          })
        }
      }
    }
    </script>
    <style scoped lang="scss">
    
    </style>
  • 相关阅读:
    CSS3的box-sizing属性
    html5 --基础笔记2
    html5--基础笔记
    CSS3--阴影,渐变,背景图片
    响应式布局--流式布局
    angular中的this指向问题
    angular中控制器之间的通讯方式
    angular中的$http配置和参数
    console
    h5表单验证的css和js方法
  • 原文地址:https://www.cnblogs.com/javascript9527/p/12555290.html
Copyright © 2011-2022 走看看