vue多图片上传组件


<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多图片上传组件的更多相关文章
- vue图片上传组件
前言:很多项目中都需要用到图片上传功能,而其多处使用的要求,为了避免重复造轮子,让我决定花费一些时间去深入了解,最终封装了一个vue的图片上传组件.现将总结再次,希望有帮助. Layout <d ...
- vue 阿里云上传组件
vue 阿里云上传组件 Vue.js上传图片到阿里云OSS存储 测试项目git地址 本测试项目启动方法 示例链接 组件配置项 实践解释 本文主要介绍如何 在vue项目中使用web 直传方式上传阿里云o ...
- Jquery图片上传组件,支持多文件上传
Jquery图片上传组件,支持多文件上传http://www.jq22.com/jquery-info230jQuery File Upload 是一个Jquery图片上传组件,支持多文件上传.取消. ...
- H5拍照、选择图片上传组件核心
背景 前段时间项目重构,改成SSR的项目,但之前用的图片选择上传组件不支持SSR(server-side-render).遂进行了调研,发现很多的工具.但有的太大,有的使用麻烦,有的不满足使用需求.决 ...
- 微信小程序简单封装图片上传组件
微信小程序简单封装图片上传组件 希望自己 "day day up" -----小陶 我从哪里来 在写小程序的时候需要上传图片,个人觉得官方提供的 Uploader 组件不是太好用, ...
- 基于Node的React图片上传组件实现
写在前面 红旗不倒,誓把JavaScript进行到底!今天介绍我的开源项目 Royal 里的图片上传组件的前后端实现原理(React + Node),花了一些时间,希望对你有所帮助. 前端实现 遵循R ...
- 分享一个react 图片上传组件 支持OSS 七牛云
react-uplod-img 是一个基于 React antd组件的图片上传组件 支持oss qiniu等服务端自定义获取签名,批量上传, 预览, 删除, 排序等功能 需要 react 版本大于 v ...
- vue 剪切图片上传头像,使用 cropperjs 实现
我使用的是vue,移动端的项目. 官网地址:cropperjs GitHub地址:https://github.com/fengyuanchen/cropperjs/blob/master/READM ...
- 图片上传组件webuploader
前端组件webuploader 当时也是搞了很久参考这种demo,但是没记.现在事后大致总结下.直接上大概代码(我使用asp.net MVC来做的): 执行顺序:(get)Record/Add——A ...
- vux-uploader 图片上传组件
1.网址:https://github.com/greedying/vux-uploader 2.安装 npm install vux-uploader --save npm install --sa ...
随机推荐
- kali 更新到最新版(测试中...)
# 确认源 (下面用阿里云的源举例) echo "deb https://mirrors.aliyun.com/kali kali-rolling main non-free contrib ...
- Skywalking安装
https://www.cnblogs.com/duanxz/p/15602842.html
- Flutter 中的普通路由、普通路由传值、 命名路由、命名路由传值
一.Flutter 中的路由 Flutter 中的路由通俗的讲就是页面跳转.在 Flutter 中通过 Navigator 组件管理路由导航.并提供了管理堆栈的方法.如:Navigator.push ...
- 栈和寄存器虚拟机比较(以python和lua为例)
指令长度 python python的指令定长,长度为16bit,其中8bit操作码,8bit操作数. ///@file: Python-3.6.0\Include\code.h typedef ui ...
- Grafana + Prometheus + Mysqld_exporter 监控 Mysql
最近研究了对于Mysql的监控,感觉Prometheus还是挺强大的,有各种适配的度量导出工具,Mysqld_exporter也是旗下的一款工具,可以在Prometheus官网下载. 因为本机电脑用的 ...
- CSP-J入门组
setw(2) cout<<setw(2) //设置后面显示字符的宽度为2 cout<<fixed<<setprecision(6)<<变量名;//设置 ...
- leetcode 98. 验证二叉搜索树 【一遍dfs】【时间击败99.72%】【内存击败94.23%】
复用left[],[时间击败73.33%]-->[时间击败99.72%] [内存击败36.17%]-->[内存击败94.23%] dfs(r)返回值=new long[]{包括r节点的子树 ...
- WCF部署HTTP错误404.3
错误:WCF部署HTTP错误404.3-Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加MIME映射. 解决步骤如下: 控制面板-& ...
- Python 封装cmd 执行命令
1.利用shell中执行成功返回0 失败非零 封装成函数 # coding: utf-8 from subprocess import Popen, PIPE, STDOUT import sys ...
- Python3注释
Python中的注释有单行注释和多行注释: python中单行注释以#开头,例如: #这是一个注释 print("hello,word!") 多行注释用三个单引号'''或者三个双引 ...