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 ...
随机推荐
- fpga always赋值
- Windows Defender锁定UI
计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender Security Center 看下这个项下的子项有没有被添加值 ...
- Arrays.sort()降序排序
默认的Java.util包中的Arrays.sort(),可以实现对java中的基本数据类型(byte.char.short.int.long.float.double.boolean)的数组进行升序 ...
- [Github]获取github ID号
[Github]获取github ID号 https://api.github.com/users/ + 你的账户名称 实例:我github账号叫iBoundary. https://api.gith ...
- 查询dockerhub中某镜像所有版本
curl https://registry.hub.docker.com/v1/repositories/${imagename}/tags | tr -d '[[]" ]' | tr '} ...
- Servicemonitor监控自带metrics接口和无metrics接口
前言: servicemonitor监控存在两种情况: 1.有metrics ,创建service+servicemonitor配置 2.无metrics 配置exporter,exporter进行 ...
- 通过nft持有大户地址获取正常交易和内部交易
/*内部交易*/------------ CREATE TABLE `internal_txlist` ( `blockNumber` varchar(255) DEFAULT NULL, `tx_t ...
- vue v-for 使用
html <div> <el-button @click="addListItem" type="primary" style="p ...
- python 的sys.argv 和 sys.path.append() 用法和PYTHONPATH环境变量
sys.argv 我们编写一个测试用例test.py ,内容如下 imoprt sys a = sys.argv b = len(sys.argv) c = sys.argv[0] d = sys.a ...
- Oracle查看异常未提交事务
1.查看归档日志都有哪些 SELECT * from v$archived_log 2.查看某个SCN号的归档文件是否存在 SELECT * from v$archived_log WHERE 113 ...