开始的时候 找不到this了,后来想起来要用 ES6的箭头函数 就有this了

reader.onload = e => {
// 读取到的图片base64 数据编码 将此编码字符串传给后台即可
// console.info('e', e)
// console.info('e.target.result', e.target.result)
// console.info('modalVmodel', format)
this.base64 = e.target.result
// console.info('this.base64', _this.base64)
}

-----------------------

<!--
* @description 上传图片
* @fileName camera.vue
* @author 彭成刚
* @date // ::
* @version V1.0.0
!-->
<template>
<div>
<Drawer title="上传照片"
class="uploadPhotoDrawerClass"
v-model="drawerVmodel"
width=""
:mask-closable="false">
<div class='divFormClass'> <Upload :action="'localhost'"
:show-upload-list="false"
ref='upload'
name="uploadFile"
type="drag"
:before-upload="handleBeforeUpload">
<!-- :data='upData' -->
<div style="padding: 20px 0">
<Icon type="ios-cloud-upload"
size=""
style="color: #3399ff"></Icon>
<p>选择 jpg 文件</p>
</div> </Upload>
<div style="margin:10px;">{{xFile.name}}</div> </div>
<div class='demo-drawer-footer'>
<Button @click="modalCancel"
style='margin-right:10px;'>关闭</Button> <Button type="primary"
@click="modalSave">保存</Button> </div>
</Drawer>
<!-- <Modal @on-cancel="modalCancel"
class="uploadPhoto"
v-model="modalVmodel"
width=""
:mask-closable="false"
title="上传图片">
<div class='divFormClass'> </div> <div slot="footer">
<Button @click="modalCancel">关闭</Button> <Button type="primary"
@click="modalSave">保存</Button> </div>
</Modal> -->
</div>
</template> <script>
export default {
data () {
return {
xFile: {
name: ''
},
base64: '',
drawerVmodel: false,
modalVmodel: false
}
}, components: {}, computed: {}, mounted () {
this.drawerVmodel = true
}, methods: {
handleBeforeUpload (item) {
let _this = this
let warningStr = ''
let format = ['jpg']
if (this.checkFormat(item.name, format)) { warningStr += '文件格式不符,请上传jpg格式 ' }
if (this.checkSize(item.size, )) { warningStr += '文件大小超过5M,请检查后重新上传!' }
if (warningStr.length !== ) {
this.$Message.warning({
content: warningStr,
duration: ,
closable: true
})
}
if (warningStr.length === ) {
this.xFile = item
console.info('this.xFile', this.xFile)
let reader = new FileReader()
reader.readAsDataURL(item)
// console.info('reader', item)
reader.onload = function (e) {
// 读取到的图片base64 数据编码 将此编码字符串传给后台即可
// console.info('e', e)
// console.info('e.target.result', e.target.result)
// console.info('modalVmodel', format)
_this.base64 = e.target.result
// console.info('this.base64', _this.base64)
}
}
return false
},
checkSize (size, maxSize) {
// size 单位是byte maxSize 单位是mb
let maxSizeByte = maxSize * *
if (size > maxSizeByte) {
return true
} else {
return false
}
},
checkFormat (fileName, format) {
let index = fileName.lastIndexOf('.')
let suffix = fileName.substr(index + )
// console.info('suffix', suffix)
let ret = true
format.some((item, index, arr) => {
if (item === suffix) {
ret = false
}
})
return ret
},
modalCancel () {
this.drawerVmodel = false
},
modalSave () {
console.info('this.base64', this.base64)
if (this.base64 === '') {
this.$Message.warning('未上传照片')
} else {
this.$emit('save-base64', this.base64)
}
this.modalCancel()
}
}
} </script>
<style lang='less'>
.ivu-message {
z-index: !important;
}
// .uploadPhoto {
// .divFormClass {
// height: calc(~"100vh - 350px");
// overflow-y: auto;
// padding-right: 15px;
// }
// }
.uploadPhotoDrawerClass {
.ivu-drawer-mask {
z-index: !important;
}
.ivu-drawer-wrap {
z-index: !important;
} .demo-drawer-footer {
width: %;
position: absolute;
bottom: ;
left: ;
border-top: 1px solid #e8e8e8;
padding: 10px 16px;
text-align: right;
background: #fff;
}
.divFormClass {
height: calc(~"100vh - 140px");
overflow-y: auto;
padding-right: 15px;
}
}
</style>

iview upload 上传图片 不传服务器 转 base64的更多相关文章

  1. kindeditor修改图片上传路径-使用webapi上传图片到图片服务器

    kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 在这里我着重介绍一些使用kindeditor修改图片上传路径并通过webapi上传图片到图片服务器的方案. 因为我使用的 ...

  2. kindeditor扩展粘贴图片功能&修改图片上传路径并通过webapi上传图片到图片服务器

    前言 kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 而kindeditor却对图片的处理不够理想. 本篇博文需要解决的问题有两个: kindeditor扩展粘贴图片功 ...

  3. kindeditor扩展粘贴截图功能&修改图片上传路径并通过webapi上传图片到图片服务器

    前言 kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 而kindeditor却对图片的处理不够理想. 本篇博文需要解决的问题有两个: kindeditor扩展粘贴图片功 ...

  4. iview Upload组件多个文件上传

    使用  iview Upload 上传组件 手动上传 包括单个文件和多个文件 思路:创建一个数组 把需要上传的文件 push到这个数组里面 1.引用组件 2.手动上传,根据官方文档 设置:before ...

  5. iview upload on-format-error 事件 在 before-upload 事件 之后,导致在before里面阻止上传后,监测事件失效,需要自己手工写

    iview upload on-format-error 事件 在 before-upload 事件 之后,导致在before里面阻止上传后,监测事件失效,需要自己手工写

  6. php工作笔记1-数组常用方法总结,二维数组的去重,上传图片到oss服务器

    1.二维数组去重,生成二维数组 private function array_unique_fb($array2D){ $data = array(); foreach($array2D  as $k ...

  7. IOS 视频.图片上传服务器

    //上传视频 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];    manager.requestSerializer. ...

  8. html+php上传图片文件到服务器

    html+php上传图片文件到服务器 一.html代码 <body> <form action="" method="post" enctyp ...

  9. 导出HTML5 Canvas图片并上传服务器功能

    这篇文章主要介绍了导出HTML5 Canvas图片并上传服务器功能,文中通过实例代码给大家介绍了HTML5 Canvas转化成图片后上传服务器,代码简单易懂非常不错,具有一定的参考借鉴价值,需要的朋友 ...

随机推荐

  1. MongoDB复制集安全认证

    之前我有一篇博客写的是“node.js通过权限验证连接MongoDB”,这篇博客上提到如何在启动文件中通过配置auth参数来开启权限认证,但这种认证方式只适合单机节点,当我们使用复制集时应该怎么开启权 ...

  2. bzoj1038&&500AC!

    序列dp 先开始想了一个类似区间dp的东西...少了一维 然后发现似乎不太对,因为女生的最大差和男生的最大差并不相等 dp[i][j][x][y]表示当前有i个人,j个男生,男生和女生的后缀最大差是x ...

  3. 6-10 SVM支持向量机1

    都是特征加上分类器.还将为大家介绍如何对这个数据进行训练.如何训练得到这样一组数据. 其实SVM支持向量机,它的本质仍然是一个分类器.既然是一个分类器,它就具有分类的功能.我们可以使用一条直线来完成分 ...

  4. POJ1787 【完全背包+物品计数+路径输出】

    题意: 有1,5,10,25四种硬币,给每种硬币的数量和要组合成的价值,求刚好达到价值时用的硬币最多,然后还要输出具体的用的数量 前言: 一开始是偶然看见了kuangbin爷的题解说是完全背包+路径, ...

  5. 框架基础:关于ajax设计方案(三)---集成ajax上传技术

    之前发布了ajax的通用解决方案,核心的ajax发布请求,以及集成了轮询.这次去外国网站逛逛,然后发现了ajax level2的上传文件,所以就有了把ajax的上传文件集成进去的想法,ajax方案的l ...

  6. iOS音频与视频的开发(二)- 使用AVAudioRecorder进行录制音频

    1.使用AVAudioRecorder录制视频 AVAudioRecorder与AVAudioPlayer类似,它们都属于AVFoundation的类.AVAudioRecorder的功能类似于一个录 ...

  7. 求导四则运算以及三角函数求导 Derivative formulas

    对特定函数的求导. 1:sin(x) 对其进行求斜率.带入公式得:[ sin(x+Δx)- sin(x)]/Δx  = [ sinx*cosΔx + cosx*sinΔx -sin x ]/ Δx = ...

  8. 为什么wait,notify和notifyAll要与synchronized一起使用?

    https://blog.csdn.net/qq_39907763/article/details/79301813 Object.wait(),Object.notify(),Object.noti ...

  9. FZu Problem 2236 第十四个目标 (线段树 + dp)

    题目链接: FZu  Problem 2236 第十四个目标 题目描述: 给出一个n个数的序列,问这个序列内严格递增序列有多少个?不要求连续 解题思路: 又遇到了用线段树来优化dp的题目,线段树节点里 ...

  10. UVA - 11082 Matrix Decompressing

    2. B - Matrix Decompressing 题意:定义一个R*C的正整数矩阵(1<=R,C<=20),设Ai为前i行所有元素之和,Bi为前i列所有元素之和. 题目已知R,C和数 ...