<template>
<!--
上传控件
用法:
<upload-widget v-model="imgUrl"></upload-widget>
-->
<div class="clearfix">
<a-upload
:action="manageApi + '/thumbController/upload.do'"
:data="fileUrl"
list-type="picture-card"
:file-list="fileInfos"
:headers="headers"
@preview="handlePreview"
@change="handleChange"
:remove="handelRemove"
accept="image/*"
:showUploadList="{ showPreviewIcon: this.showPreviewIcon, showRemoveIcon: this.showRemoveIcon }"(显示眼睛和隐藏判断)
>
<a-icon type="plus" />
<div class="ant-upload-text">Upload</div>
</a-upload>
<!-- 图片预览 -->
<a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
<img alt="example" style="width: 100%; height: 100%" :src="previewImage" />
</a-modal>
</div>
</template> <script>
import axios from 'axios'; /**把图片转成BASE64 */
function getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
});
}
export default {
name: 'UploadAlbumWidget',
model: {
prop: 'fileList',
event: 'change',
},
props: {
//最大上传数量
maxUploadNum: {
type: Number,
default: 1,
},
/**文件列表 */
fileList: {
type: [Array, String],
default() {
return '';
},
},
type: {
type: String,
},
showPreviewIcon: {
type: Boolean,
default() {
return true;
},
},
showRemoveIcon: {
type: Boolean,
default() {
return true;
},
},

},
data() {
return {
headers: {}, //头
previewVisible: false,
previewImage: '',
fileInfos: [], //上传文件
};
},
created() {
// this.initVModelData();
/**默认添加验证token */
this.headers = {
token: this.store.user.token,
adminToken: this.store.admin.token,
};

},
methods: {
fileUrl() {
return {
type: this.type,
};
},
/**处理初始v-model数据 */
initVModelData() {
let that = this;
console.log('initVModelData', this.fileList);
//判断文件上传是否多个
if (this.fileList) {
//多文件
that.fileList.forEach((fl, index) => {
that.fileInfos.push({
uid: '-' + index,
name: '图集',
status: 'done',
url: process.env.VUE_APP_IMAGE_SERVER + fl.imgPath,(process.env.VUE_APP_IMAGE_SERVER =》》》》


thumbUrl: process.env.VUE_APP_IMAGE_SERVER + fl.thumbPath,
response: {
data: [{ id: fl.id }],
},
});
});
// }
}
},
handleCancel() {
this.previewVisible = false;
},
/**预览图 */
async handlePreview(file) {
if (!file.url && !file.preview) {
file.preview = await getBase64(file.originFileObj);
}
console.log('handlePreview', file);
this.previewImage = file.thumbUrl || file.preview;
this.previewVisible = true;
}, handleChange({ fileList }) {
this.fileInfos = fileList;
},
handelRemove(file) {
console.log('handelRemove ');
let result = axios({
method: 'post',
url: `thumbController/del.do`,
data: {
id: file.response.data[0].id,
},
});
if (result.data.code == 200) {
this.$message.success('删除成功');
} else {
this.$message.error(result.data.message);
return false;
}
},
},
watch: {
/**检测v-model数据是否发生改变 */
fileList(val) {
this.initVModelData();
},
},
};
</script> <style scoped>
.ant-upload-select-picture-card i {
font-size: 32px;
color: #999;
} .ant-upload-select-picture-card .ant-upload-text {
margin-top: 8px;
color: #666;
}
</style>

vue多图片上传组件的更多相关文章

  1. vue图片上传组件

    前言:很多项目中都需要用到图片上传功能,而其多处使用的要求,为了避免重复造轮子,让我决定花费一些时间去深入了解,最终封装了一个vue的图片上传组件.现将总结再次,希望有帮助. Layout <d ...

  2. vue 阿里云上传组件

    vue 阿里云上传组件 Vue.js上传图片到阿里云OSS存储 测试项目git地址 本测试项目启动方法 示例链接 组件配置项 实践解释 本文主要介绍如何 在vue项目中使用web 直传方式上传阿里云o ...

  3. Jquery图片上传组件,支持多文件上传

    Jquery图片上传组件,支持多文件上传http://www.jq22.com/jquery-info230jQuery File Upload 是一个Jquery图片上传组件,支持多文件上传.取消. ...

  4. H5拍照、选择图片上传组件核心

    背景 前段时间项目重构,改成SSR的项目,但之前用的图片选择上传组件不支持SSR(server-side-render).遂进行了调研,发现很多的工具.但有的太大,有的使用麻烦,有的不满足使用需求.决 ...

  5. 微信小程序简单封装图片上传组件

    微信小程序简单封装图片上传组件 希望自己 "day day up" -----小陶 我从哪里来 在写小程序的时候需要上传图片,个人觉得官方提供的 Uploader 组件不是太好用, ...

  6. 基于Node的React图片上传组件实现

    写在前面 红旗不倒,誓把JavaScript进行到底!今天介绍我的开源项目 Royal 里的图片上传组件的前后端实现原理(React + Node),花了一些时间,希望对你有所帮助. 前端实现 遵循R ...

  7. 分享一个react 图片上传组件 支持OSS 七牛云

    react-uplod-img 是一个基于 React antd组件的图片上传组件 支持oss qiniu等服务端自定义获取签名,批量上传, 预览, 删除, 排序等功能 需要 react 版本大于 v ...

  8. vue 剪切图片上传头像,使用 cropperjs 实现

    我使用的是vue,移动端的项目. 官网地址:cropperjs GitHub地址:https://github.com/fengyuanchen/cropperjs/blob/master/READM ...

  9. 图片上传组件webuploader

    前端组件webuploader 当时也是搞了很久参考这种demo,但是没记.现在事后大致总结下.直接上大概代码(我使用asp.net  MVC来做的): 执行顺序:(get)Record/Add——A ...

  10. vux-uploader 图片上传组件

    1.网址:https://github.com/greedying/vux-uploader 2.安装 npm install vux-uploader --save npm install --sa ...

随机推荐

  1. 在uniapp中,定义导航栏左侧,右侧按钮

    在page.json中 代码: { "path": "pages/pandian", "style": { "navigation ...

  2. zabbix中文显示乱码解决

    问题zabbix使用中文显示,"监测-->图形"查看资源使用情况时会有乱码 解决问题1.修改配置文件(文件位置:$zabbix_path/include/defines.in ...

  3. PMP项目启动会与开工会议

    转载https://www.cnblogs.com/yanpeng1991/p/11391805.html 项目启动会(project initiating meeting)与项目开工会(kick-o ...

  4. M1处理器的电脑xcode模拟器编译报错问题详解及解决方案

    在M1芯片的苹果电脑中使用Xcode编译模拟器时,可能会碰到如下报错: 原因是由于M1模拟器架构是arm64架构,而Intel芯片是x86_64的架构,从而导致编译出现了问题. 这些报错,都是是由于项 ...

  5. 正确引用R及R包

    R版本不断更新,为保证数据可重复性,引用R时需标注出对应的R版本.那么如何引用呢? 打开R,键入citation(),得到对应的版本引用信息. To cite R in publications us ...

  6. apk反编译工具--dex2jar

    dex2jar 2.1 https://github.com/pxb1988/dex2jar/releases 链接: https://pan.baidu.com/s/1ZU16mPE_QNhzWxF ...

  7. 前端实现HTML转PDF下载的两种方式

    原文链接:https://www.jianshu.com/p/56680ce1cc97 方式一:使用html2canvas和jspdf插件实现 该方式是通过html2canvas将HTML页面转换成图 ...

  8. Ubuntu18.04 右上角网络连接消失问题记录

    问题记录 因为一块板子要访问远程桌面,需要联网才行,然后发现桌面右上角的网络连接标志不见了,而且无论用usb共享网路,或者是无线网卡,都连不上网. 首先想是不是硬件的问题,给系统重新装了一个ubunt ...

  9. vscode调试openresty

    一.快速上手 1.软件下载 官网地址:https://code.visualstudio.com/ 安装视频:https://code.visualstudio.com/docs/getstarted ...

  10. xmapp

    下载软件 并开启Apache 创建文本 `<?php echo " 姓名:丁文博 学号:20211306 才艺:打篮球 专业:信息安全 学校:北京电子科技学院 ";` 在网页 ...