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 ...
随机推荐
- python3.10.0字符串基础
字符串支持 索引 (下标访问),第一个字符的索引是 0.单字符没有专用的类型,就是长度为一的字符串: >>> word = 'Python' >>> word[0] ...
- c# winform调用osk系统自带软键盘
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- python logging模块学习
logging 是对程序运行中的日志进行输出记录,用户在程序中设置在哪个地方输出什么信息,方便进行之后问题的排查. logging输出有两种方式:输出至控制台 . 输出至文件 输出至控制台: impo ...
- unity 变体 随手记
1 #pragma multi_compile AAA BBB#pragma multi_compile CCC DDDAAA CCCAAA DDDBBB CCCBBB DDD------------ ...
- react backend and frontend download file
import { View as ViewFile} from '@/api/SafetyRule'; const Handler_DownLoadFile = (Id:number,IsEngli ...
- CF513F2 题解
题意 传送门 有 \(a+b+1\) 个会动的棋子,在一个大小为 \(n\times m\) 的棋盘上,棋盘上有一些点有障碍.棋子中,有 \(a\) 个红色棋子,\(b\) 个蓝色棋子,和 \(1\) ...
- 881. 救生艇 (Medium)
问题描述 881. 救生艇 (Medium) 给定数组 people . people[i] 表示第 i 个人的体重 , 船的数量不限,每艘船可以承载的最大重量为 limit. 每艘船最多可同时载两人 ...
- 1996. 游戏中弱角色的数量 (Medium)
问题描述 1996. 游戏中弱角色的数量 (Medium) 你正在参加一个多角色游戏,每个角色都有两个主要属性: 攻击 和 防御 .给你一个二维整数数组 properties ,其中 properti ...
- unity Dotween Path 设置路径平滑加旋转平滑
Waiter.transform.DOPath(list.ToArray(), 3f * (index / 2.0f + 1.0f), PathType.CatmullRom).SetLookAt(0 ...
- OSI网络七层模型简明教程
如果你读过计算机专业,或者学习过网络通信,那你一定听说过 OSI 模型,它曾无数次让你头大.OSI 是 Open System Interconnection 的缩写,译为"开放式系统互联& ...