slot="wage" slot-scope="text,record" :ref="record.index" :model="record" :rules="rules" style="width:300px;height:40px" >
export default {
name: 'tableForm',
data() {
let validateWage = (rule, value, callback) => {
let reg = /^[+]?[0-9]+(\.[0-9]{1,3})?$/
if (value === '') {
callback(new Error('请输入值'))
} else if (!reg.test(value)) {
callback(new Error('请输入整数或小数'))
} else {
callback()
}
}
return {
form: {},
rules: {
wage: [{ validator: validateWage, trigger: 'change' }]
},
columns: [
{
title: '姓名',
dataIndex: 'name',
key: 'name',
align: 'center',
scopedSlots: { customRender: 'name' }
},
{
title: '工资',
dataIndex: 'wage',
width: '300px',
key: 'wage',
align: 'center',
scopedSlots: { customRender: 'wage' }
},
{
title: '操作',
key: 'action',
align: 'center',
scopedSlots: { customRender: 'action' }
}
],
data: [
{ key: 1, wage: '', name: '张三', index: 'form1' },
{ key: 2, wage: '', name: '张三', index: 'form2' },
{ key: 3, wage: '', name: '张三', index: 'form3' }
]
}
},
methods: {
submit() {
let submitFlag = false
for (var key in this.$refs) {
this.$refs[key].validate((valid) => {
if (valid) {
// alert('submit!')
} else {
submitFlag = true
return false
}
})
}
if (!submitFlag) {
alert('submit!')
}
}
}
}