1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| 子组件 upload.vue <template> <div class="con_form"> <el-form ref="addForm" :model="addForm" class="demo-comCreditForm" label-width="200px"> <el-form-item label="企业名称:" prop="name"> <el-input v-model="addForm.name" placeholder="转贷机构名称" /> </el-form-item> <el-form-item label="统一社会信用代码:" prop="code"> <el-input v-model="addForm.code" placeholder="请输入统一社会信用代码" /> </el-form-item> <div class="upload_icon"> <el-form-item label="上传:" prop="addForm"> <el-upload :auto-upload="false" :limit="limitCount" :on-remove="handleRemove" :on-change="onChange" :on-success="handleSuccess" :file-list="fileList" :data="uploadData" :before-upload="beforeAvatarUpload" action="#" class="avatar-uploader" list-type="picture-card" accept="image/jpg,image/jpeg,image/png"> <img v-if="url" :src="url" class="el-upload-list__item-thumbnail"></img> <i v-else slot="default" class="el-icon-plus" /> </el-upload> <div class="el-upload__tip">jpg.jpeg、png格式,大小5M以内</div> </el-form-item> </div> </el-form> </div> </template> <script> export default { data() { return { limitCount: 1, url: '', onChangeImgUrl: '', uploadData: { name: 'testFile' }, fileList: [], addForm: { name: '', code: '' } } }, watch: { onChangeImgUrl: { handler(newName) { var aa = document.querySelector('.el-upload--picture-card') if (newName) { aa.style.display = 'none' } else { setTimeout(() => { aa.style.display = 'inline-block' }, 1100) } } } }, methods: { onChange(file, fileList) { this.onChangeImgUrl = file.url }, handleRemove(file, fileList) { this.onChangeImgUrl = '' }, handleSuccess(file, fileList) { this.$set(this.myForm, 'netTgThumbnail', fileList.response.bean.result.fileUrlPath) }, beforeAvatarUpload(file) { const isLt5M = file.size / 1024 / 1024 < 5 if (!isLt5M) { this.$message.error('上传头像图片大小不能超过 2MB!') } return isLt5M } } } </script> <style scoped lang="scss"> /deep/.upload_icon .el-form-item__content { position: relative; height: 190px; } .avatar-uploader { width: 145px; height: 145px; position: absolute; left: 0; top: 0; } .con_form .upload_icon .el-form-item__content .el-upload__tip { position: absolute; left: 0; bottom: 0; color: red; } </style>
|