vue+elementUI实现图片上传功能

<el-form-item label="图片" prop="logo"> <el-upload v-if="optype==0" :action="'/upload'" accept=".jpg, .png" list-type="picture-card" :file-list="fileLists" :on-preview="handlePictureCardPreview" :on-success="success" :on-remove="handleRemove"> <i></i> </el-upload> <!--大图弹出框--> <el-dialog :visible.sync="imgDialogVisible" size="full" :modal="false" title="查看大图片"> <img :src="dialogImageUrl" alt=""> </el-dialog> </el-form-item>

2、定义

dialogImageUrl: '', imgDialogVisible: false, fileLists: [],

3、在需要使用的方法中给fileLists[]赋值

vm.fileLists = []; if (row.logo != undefined && row.logo != "") { vm.fileLists.push({url:row.logo}); }

4、其他几个属性的方法

//删除图片 handleRemove(file, fileList) { this.form.logo='' }, //查看大图 handlePictureCardPreview(file) { this.dialogImageUrl = file.url; this.imgDialogVisible = true; }, //图片上传成功 success(response, file, fileList) { this.fileLists = []; this.fileLists = [file] this.form.logo = file.response.result; },

5、图片上传的位置和路径是存在不同的表中。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/6ee2e2200a7c8184f79fbfc5f477da65.html