前端记录6--Element中upload组件使用多个时绑定index
问题描述
一般我们使用el-upload,是这种用法
1 2 3 4 5 6 7 8 9
| <el-upload class="avatar-uploader" action="#" :show-file-list="false" :http-request="fileUpLoad" > <img v-if="form.credentialsRealUrl" :src="form.credentialsRealUrl" class="avatar"> <i v-else class="el-icon-plus avatar-uploader-icon"></i> </el-upload>
|
通过实现http-request方法,来实现上传操作,然后将图片地址赋值给一个变量
但是现在,在使用el-upload过程中,有这么一个需求
会有动态数量的upload框,所以不能用写死的fileUpLoad方法,因为默认方法只有一个option参数,没有其他的可选参数,所以我们不知道上传的图片地址到底是该给哪一个变量
解决办法:
1
| :http-request="(option)=>{return fileUpLoad(option,index)}"
|
这样可以增加一个index变量,从而去进行一些赋值逻辑了
前Android/Vue开发,现Infra从业人员,主营监控/AWS