- element
<el-form-item label="上传附件" prop="fileList">
<el-upload
:on-success="upSuccess"
:file-list="inputForm.fileList"
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
</el-form-item>
data () {
return {
inputForm: {
fileList: []
},
rules: {
fileList: [{
message: '请上传附件',
trigger: 'change',
required: true
}]
}
}
}
upSuccess (file, fileList) {
this.inputForm.fileList.push(fileList)
this.$refs.inputForm.validateField('fileList')
}
- iview
<FormItem label="附件:" prop="fileList">
<Upload
v-model="tableList.fileList"
:on-success="handleFileLoadSuccess"
><Button type="primary">上传</Button></Upload>
</FormItem>
const validateUpload = (rule, value, callback) => {
if (this.attachmentIDs.length>0) {
callback();
} else {
callback(new Error('请选择要上传的文件'));
}
}
data () {
return {
tableList: {
fileList: null
},
attachmentIDs: [],
rules: {
fileList: [{ required: true, validator: validateUpload, trigger: 'change' }]
}
}
}
handleFileLoadSuccess(response, file, fileList){
this.attachmentIDs.push(file)
}
另外列表关闭时需要清除,在Model上面加上@on-visible-change="ModelSaveclose"
ModelSaveclose() {
this.tableList.fileList = null
this.attachmentIDs = []
},
|