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

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

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

  1. <!--
  2. * @description 上传图片
  3. * @fileName camera.vue
  4. * @author 彭成刚
  5. * @date // ::
  6. * @version V1.0.0
  7. !-->
  8. <template>
  9. <div>
  10. <Drawer title="上传照片"
  11. class="uploadPhotoDrawerClass"
  12. v-model="drawerVmodel"
  13. width=""
  14. :mask-closable="false">
  15. <div class='divFormClass'>
  16.  
  17. <Upload :action="'localhost'"
  18. :show-upload-list="false"
  19. ref='upload'
  20. name="uploadFile"
  21. type="drag"
  22. :before-upload="handleBeforeUpload">
  23. <!-- :data='upData' -->
  24. <div style="padding: 20px 0">
  25. <Icon type="ios-cloud-upload"
  26. size=""
  27. style="color: #3399ff"></Icon>
  28. <p>选择 jpg 文件</p>
  29. </div>
  30.  
  31. </Upload>
  32. <div style="margin:10px;">{{xFile.name}}</div>
  33.  
  34. </div>
  35. <div class='demo-drawer-footer'>
  36. <Button @click="modalCancel"
  37. style='margin-right:10px;'>关闭</Button>
  38.  
  39. <Button type="primary"
  40. @click="modalSave">保存</Button>
  41.  
  42. </div>
  43. </Drawer>
  44. <!-- <Modal @on-cancel="modalCancel"
  45. class="uploadPhoto"
  46. v-model="modalVmodel"
  47. width=""
  48. :mask-closable="false"
  49. title="上传图片">
  50. <div class='divFormClass'>
  51.  
  52. </div>
  53.  
  54. <div slot="footer">
  55. <Button @click="modalCancel">关闭</Button>
  56.  
  57. <Button type="primary"
  58. @click="modalSave">保存</Button>
  59.  
  60. </div>
  61. </Modal> -->
  62. </div>
  63. </template>
  64.  
  65. <script>
  66. export default {
  67. data () {
  68. return {
  69. xFile: {
  70. name: ''
  71. },
  72. base64: '',
  73. drawerVmodel: false,
  74. modalVmodel: false
  75. }
  76. },
  77.  
  78. components: {},
  79.  
  80. computed: {},
  81.  
  82. mounted () {
  83. this.drawerVmodel = true
  84. },
  85.  
  86. methods: {
  87. handleBeforeUpload (item) {
  88. let _this = this
  89. let warningStr = ''
  90. let format = ['jpg']
  91. if (this.checkFormat(item.name, format)) { warningStr += '文件格式不符,请上传jpg格式 ' }
  92. if (this.checkSize(item.size, )) { warningStr += '文件大小超过5M,请检查后重新上传!' }
  93. if (warningStr.length !== ) {
  94. this.$Message.warning({
  95. content: warningStr,
  96. duration: ,
  97. closable: true
  98. })
  99. }
  100. if (warningStr.length === ) {
  101. this.xFile = item
  102. console.info('this.xFile', this.xFile)
  103. let reader = new FileReader()
  104. reader.readAsDataURL(item)
  105. // console.info('reader', item)
  106. reader.onload = function (e) {
  107. // 读取到的图片base64 数据编码 将此编码字符串传给后台即可
  108. // console.info('e', e)
  109. // console.info('e.target.result', e.target.result)
  110. // console.info('modalVmodel', format)
  111. _this.base64 = e.target.result
  112. // console.info('this.base64', _this.base64)
  113. }
  114. }
  115. return false
  116. },
  117. checkSize (size, maxSize) {
  118. // size 单位是byte maxSize 单位是mb
  119. let maxSizeByte = maxSize * *
  120. if (size > maxSizeByte) {
  121. return true
  122. } else {
  123. return false
  124. }
  125. },
  126. checkFormat (fileName, format) {
  127. let index = fileName.lastIndexOf('.')
  128. let suffix = fileName.substr(index + )
  129. // console.info('suffix', suffix)
  130. let ret = true
  131. format.some((item, index, arr) => {
  132. if (item === suffix) {
  133. ret = false
  134. }
  135. })
  136. return ret
  137. },
  138. modalCancel () {
  139. this.drawerVmodel = false
  140. },
  141. modalSave () {
  142. console.info('this.base64', this.base64)
  143. if (this.base64 === '') {
  144. this.$Message.warning('未上传照片')
  145. } else {
  146. this.$emit('save-base64', this.base64)
  147. }
  148. this.modalCancel()
  149. }
  150. }
  151. }
  152.  
  153. </script>
  154. <style lang='less'>
  155. .ivu-message {
  156. z-index: !important;
  157. }
  158. // .uploadPhoto {
  159. // .divFormClass {
  160. // height: calc(~"100vh - 350px");
  161. // overflow-y: auto;
  162. // padding-right: 15px;
  163. // }
  164. // }
  165. .uploadPhotoDrawerClass {
  166. .ivu-drawer-mask {
  167. z-index: !important;
  168. }
  169. .ivu-drawer-wrap {
  170. z-index: !important;
  171. }
  172.  
  173. .demo-drawer-footer {
  174. width: %;
  175. position: absolute;
  176. bottom: ;
  177. left: ;
  178. border-top: 1px solid #e8e8e8;
  179. padding: 10px 16px;
  180. text-align: right;
  181. background: #fff;
  182. }
  183. .divFormClass {
  184. height: calc(~"100vh - 140px");
  185. overflow-y: auto;
  186. padding-right: 15px;
  187. }
  188. }
  189. </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. 【旧文章搬运】PspCidTable攻与防

    原文发表于百度空间,2009-03-29========================================================================== PspCi ...

  2. Ubuntu中字体的改变

    1.sudo dpkg-reconfigure console-setup 2.弹出 Configuring console-setup 界面,选择适当的编码格式,我们一般选择默认的UTF-8,选择O ...

  3. input required字段;django input输入框不填写会自动变红如何修改

    前端页面中,input不输入任何内容时,点击submit时,未填写的input会标红框,有些人还会有"该字段必填的字样"!! 什么鬼,你妹的,js也见不到,css3动画也见不到,怎 ...

  4. poj3617【贪心】

    题意: 给定长度为N的字符串S,要构造一个长度为N的字符串T串. 从S的头部删除一个字符,加到T的尾部 从S的尾部删除一个字符,加到T的尾部 目标是构造字典序尽可能小的字符串. 思路: 贪心,每次取小 ...

  5. 关于国债的一些计算: 理论TF价格1(缴款日前无付息)

    计算 ExpectedTFPrice 是一个比较复杂的计算,我们这里讨论简单的一种情况. 给定一只可交割国债bond(一般为CTD),一个国债期货tf,一个日期t(表示tf的一个交易日期,我们通过t日 ...

  6. IT兄弟连 ElasticSearch在Linux下的安装和启动、常见问题解决

    环境要求 ·      Linux(Centos 7) ·      ElasticSerach 6.6.1 ES下载 ·      下载地址:https://www.elastic.co/cn/do ...

  7. 树的直径初探+Luogu P3629 [APIO2010]巡逻【树的直径】By cellur925

    题目传送门 我们先来介绍一个概念:树的直径. 树的直径:树中最远的两个节点间的距离.(树的最长链)树的直径有两种方法,都是$O(N)$. 第一种:两遍bfs/dfs(这里写的是两遍bfs) 从任意一个 ...

  8. 如何为github已有仓库添加协议。

    在github创建开源项目的时候,github会引导开发者添加一个开源协议,直接照着操作即可.但是如果一开始没有添加开源协议,后面要怎么添加呢? 百度无果.多方打听.总结如下步骤. 1.首先,进入你的 ...

  9. 将tomcat添加到系统服务

    一.安装服务 执行“service.bat install 二.卸载服务 在命令行中进入/Tomcat路径/bin/,执行“service.bat remove”  

  10. Educational Codeforces Round 46 (Rated for Div. 2) B. Light It Up

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/B 思路:先用两个数组sumon[]和sumoff[]将亮着的灯和灭的灯累计一下. ...