el-upload 上传图片和文件并显示

el-upload 上传图片和文件并显示

一、先看页面

					//图片
					<el-form-item label="营业执照图" prop="businessLicensePhotos" ref="zhizhao2">
                        <el-upload
                            class="upload-demo"
                            :action="imageurl"
                            :on-preview="handlePreview"
                            :on-remove="handleRemove"
                            :before-remove="beforeRemove"
                            multiple
                            :limit="2"
                            name="file"
                            :on-success="handleAvatarSuccess6"
                            :on-exceed="handleExceed"
                            list-type="picture"
                            v-model="ruleForm.zhizhao"
                        >
                            <el-button size="small" type="primary">点击上传</el-button>
                        </el-upload>
                    </el-form-item>

					//文件
                    <el-form-item label="授权书" prop="authorization">
                        <el-upload
                            class="upload-demo"
                            :action="fileurl"
                            :on-success="handleAvatarSuccess7"
                            :on-preview="handlePreview"
                            :on-remove="handleRemove"
                            :before-remove="beforeRemove"
                            multiple
                            :limit="2"
                            name="file"
                            :on-exceed="handleExceed"
                            v-model="ruleForm.shouquan"
                        >
                            <el-button size="small" type="primary" style="display: inline-block">点击上传</el-button>&nbsp;&nbsp;&nbsp;
                            <div style="display: inline-block; color: #606266; font-size: 12px">(经办人不是法人时需提供此项资料)</div>
                        </el-upload>
                    </el-form-item>

二、重点来了

action是上传的接口,必填参数
name是上传的文件字段名
理解:el-upload这个组件在文件图片上传过程中其实就是发送了一个请求,action就是接收、响应请求的接口地址,name的值就是这个接口需要传的字段的名字(对应接口文档里就是下图这个意思)

在这里插入图片描述

三、在页面里应该怎么写

第一步:在data里定义
			imageurl : this.$HOST + 'api/cert/upload/image',
            fileurl : this.$HOST + 'api/cert/upload/file',
第二步:写进生命周期mounted
		this.imageurl = this.$HOST + 'api/cert/upload/image';
        this.fileurl = this.$HOST + 'api/cert/upload/file';
第三步:请求结果:用到了成功的钩子函数,res就是返回值
	handleAvatarSuccess6(res, file) {
            this.ruleForm.zhizhao = res.obj;
            this.$refs.zhizhao2.clearValidate();
        },
        handleAvatarSuccess7(res, file) {
            this.ruleForm.shouquan = res.obj;
        },
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值