ivew Upload 上传图片组件
1. 先展示一个效果图

2.代码详解
<!-- 封面缩略图 -->
<div class="pop-up-div pic">
<div class="thumbnail"><span>发布封面</span></div>
<div class="demo-upload-list" v-for="item in uploadList" :key="item.index"> // uploadList(重点)
<template >
<img :src="coverLink ? coverLink : item.path"> //图片渲染
<div class="demo-upload-list-cover">
<Icon type="ios-eye-outline" @click.native="handleView(item.name)"></Icon> // 展示默认icon
<Icon type="ios-trash-outline" @click.native="handleRemove(item)"></Icon>
</div>
</template>
</div>
<Upload
ref="upload" // dom节点
:show-upload-list= true // 默认上传显示列表
:on-success="handleSuccess" // 成功回调
:format="['jpg','png']" // 设置图片格式
:max-size="2048" // 设置图片大小
:on-format-error="handleFormatError" // 判断图片格式是否正确
:on-exceeded-size="handleMaxSize" // 限制图片大小
:before-upload="handleBeforeUpload" // 上传之前的钩子函数,可以在此限制图片的张数
type="drag" // 开启拖拽上传
name="coverImage" // multiple,加此属性可以多图片上传
:headers= "header" // 设置请求头
v-if="show"
:action="uploadCoverUrl" //上传图片接口
style="display: inline-block;width:116px;">
<div style="width: 116px;height:116px;line-height: 116px;">
<Icon type="ios-camera" size="30"></Icon> // 默认icon
</div>
</Upload> //点击为大图
<Modal title="View Image" v-model="visible" :closable="false" @on-ok="$store.state.addArticle = true" @on-cancel="$store.state.addArticle = true">
<img :src="'/' + imgName " v-if="visible" style="width: 100%;z-index:1100;"> // closable 点击model右上角,关闭模态框,默认为true,
</Modal>
<div class="warnText"> // 一些格式说明
<p>1.格式为jpg或png</p>
<p>2.且不能大于2M</p>
<p>3.建议尺寸336*160</p>
</div>
</div>
<div slot="footer">
<Button type="primary" size="large" @click="ok">确定</Button> // 信息提交按钮
</div>
data(){
uploadCoverUrl:'',
uploadList :[],
coverLink :'',
show:true,
visible: false,
header:{
'token': sessionStorage.getItem('token')
}
}
//封面缩略图 图片上传成功后的操作
handleSuccess(res, file){
let _this = this;
console.log(res)
file.path = res.data.path
file.name = _this.getNameFromLink(file.path)
_this.coverLink = file.path
_this.uploadList.push(file)
_this.show = false;
},
//判断图片格式对不对
handleFormatError (file) {
this.$Notice.warning({
title: '图片格式不正确',
desc: file.name + ' 格式不正确,请重新选择'
});
},
//限制图片大小
handleMaxSize (file) {
this.$Notice.warning({
title: '图片尺寸过大',
desc: file.name + ' 太大,最大为2M,请注意图片大小!'
});
},
//限制图片的张数
handleBeforeUpload (file) {
if(this.uploadList){
const check = this.uploadList.length < 1;
if (!check) {
this.$Notice.warning({
title: '最多上传一张图片!'
});
}
return check;
}
},
// 点击看大图
handleView(name){
console.log(name)
this.imgName = name;
this.visible = true;
this.$store.state.addArticle = false
},
// 删除一张图片
handleRemove(file){
this.uploadList.splice(file, 1);
this.show = true; //这个是显示上传的那个icon
},
//上传pdf文件 <Upload
ref="previewPdf"
:default-file-list="defaultList"
multiple
name="accessory"
:format="['pdf', '', '',]"
type="drag"
:headers= "header"
:max-size="51200"
:before-upload="handleBeforeUploadp"
:on-preview="lookPdf"
:on-success="handleSuccessPdf"
:action="uploadPdfUrl">
<div style="padding: 20px 0">
<Icon type="ios-cloud-upload" size="52" style="color: #999"></Icon>
<p>将文件拖拽至此或选择文件(最多上传50M的pdf文件)</p>
<p style="color: #07C5A3;font-weight: bold">点击上传</p>
</div>
</Upload>
// 点击查看pdf的操作
lookPdf(file){
console.log(file)
let _this = this;
let url;
if(file.response){
url = file.response.data.path
}else{
url = file.url
}
window.open(url)
},
// pdf上传成功的操作
handleSuccessPdf(res,file,fileList){
let _this = this;
console.log(fileList)
_this.$refs.previewPdf.fileList = fileList
_this.defaultList = fileList
_this.contentAccessoryIds = res.data.id
},
// pdf文件移除时候的方法
handleRemoveFile(file,fileList){
console.log(fileList)
console.log(this.defaultList.length)
this.defaultList = fileList
console.log(this.defaultList)
},
// 上传pdf文件的数量控制
handleBeforeUploadp(){
let _this = this;
console.log(_this.defaultList)
const tpl = _this.defaultList.length < 1
if(!tpl) {
_this.$Notice.warning({
title: '最多上传一个pdf文件!'
});
}
return tpl;
}, // 通过iframe上传视频
<!--视频-->
<div v-if="shiPing" class="shi-ping">
<!-- 视频 -->
<iframe v-if="!videoSrc" width="800" height="200" src="" frameborder="0"></iframe>
<div >
<div v-if="videoSrc" class="deleteFlag"><span class="float-r" @click="deleteVideo" style="backgroundColor:#333;cursor:pointer;width:32px;text-align:center;font-size:24px;">X</span> </div>
<video id="videoSec" v-if="videoSrc" :src="videoSrc" width="300" height="200" controlsList="nodownload" controls="controls"></video>
</div>
</div>
ivew Upload 上传图片组件的更多相关文章
- 为ivew的Page组件的跳页增加跳页确定按钮
首次使用vue做后台管理项目,首次使用ivew框架,好不容易所有的功能都做完了,前几天产品经理让在每个列表的跳页后面加个‘确定’按钮,说没有确定按钮有点反人类,心想那还不分分钟的事儿嘛,立马回个‘好的 ...
- 自定义input上传图片组件
自定义input上传图片组件,美化样式 前段时间因为项目需求,做过一个上传图片组件,这里分享下大致思路,希望对有需要的童鞋有所帮助~~~ 功能需求:1.上传图片限制大小.分辨率.类型 2.上传图片支持 ...
- iview upload 上传图片 不传服务器 转 base64
开始的时候 找不到this了,后来想起来要用 ES6的箭头函数 就有this了 reader.onload = e => { // 读取到的图片base64 数据编码 将此编码字符串传给后台即可 ...
- 上传图片组件封装 element ui
// element ui 文档地址: http://element.eleme.io/#/zh-CN <template> <div> <div class=" ...
- 微信小程序 - 上传图片组件
2019-01-08 更新至1.1:修复了一些问题 2019-03-14 全面更新,推荐:https://www.cnblogs.com/cisum/p/10533559.html 使用了es8的as ...
- jQuery file upload上传图片的流程
先触发_onChange[jquery.fileupload.js] _onChange: function (e) { var that = this, data = { fileInput: $( ...
- jQuery file upload上传图片出错分析
以https://github.com/blueimp/jQuery-File-Upload/blob/master/basic-plus.html为例 注释掉load-image.all.min.j ...
- ivew Upload 上传时附带的额外参数
<Upload action="/api/device/importData" :data="uploadData" :before-upload=&qu ...
- django admin upload 上传图片到oss Django Aliyun OSS2 Storage
https://github.com/xiewenya/django-aliyun-oss2-storage Install pip install django-aliyun-oss2-storag ...
随机推荐
- MySQL事务的四种隔离级别
事务的基本要素: 原子性(atomicity):事务开始后的全部操作, 要么全部执行成功,如果中间出现错误,事务回滚到事务开始前的状态. 一致性(Consistency):事务开始后,数据库的完整性约 ...
- web编程非常实用的在线工具大全---转载
代码对比/归并: http://www.matools.com/compare 正则表达式: http://www.matools.com/regex js/css压缩: http://www.mat ...
- java环境搭建与安装开发工具全教程
当前端的后台搭档是做java后台时,这时就需要自己搭建一个java开发环境,和安装eclipse了. 那么,一般这些开发环境在一个开发团队中是统一的.正规完善的公司还会有自己软件库和安装配置文档.这时 ...
- shell中#*,##*,#*,##*,% *,%% *的含义及用法
介绍下Shell中的${}.##和%%使用范例,本文给出了不同情况下得到的结果.假设定义了一个变量为:代码如下:file=/dir1/dir2/dir3/my.file.txt可以用${ }分别替换得 ...
- MariaDB学习笔记(二)
七 索引索引:索引是创建在表上的,是对数据库表中的一列或多列的值进行排序的一种结构.索引可以提高查询的速度.索引有两种存储类型: B型树索引 哈希索引I nnoDB和MyISAM支持B型树索引,MEM ...
- redis 主从复制+读写分离+哨兵
1.redis读写分离应用场景 当数据量变得庞大的时候,读写分离还是很有必要的.同时避免一个redis服务宕机,导致应用宕机的情况,我们启用sentinel(哨兵)服务,实现主从切换的功能.redis ...
- sql查询静态数据
select * from ( ,,,'高中')) AS Education ( EducationId,EducationName )
- 自从学会了 Array.reduce() ,再也离不开它
(转载)原文链接:https://juejin.im/post/5dfd9d27e51d455825129ec3 在所有后 ES6 时代的数组方法中,我觉得最难理解的就是Array.reduce( ...
- 【串线篇】MyBatis简介
一.MyBatis 和数据库进行交互:持久化层框架(SQL映射框架): 1).纯手工 从原始的JDBC----dbutils(QueryRunner)-------JdbcTemplate----xx ...
- 【串线篇】浅谈BeanFactory
BeanFactory&ApplicationContext BeanFactory: bean工厂接口,负责创建bean实例, 容器里保存的所有单例bean其实是一个map<key-- ...