vue项目内嵌入到app input type=file 坑(文件上传插件)
w问题描述:
我用vue-cli完成的一个移动端项目,内嵌到app当中,用原生的input type=file 来完成文件上传。在安卓下没有问题但是在苹果手机 上传第二次手机就会发生白屏 并无缘无故跳转。
具体原因尚未发现。
解决办法:
引用了一个vue的插件:https://lian-yue.github.io/vue-upload-component/#/zh-cn/documents#入门开始;这个是插件地址,具体使用方法以及返回值都会有一定描述,
如果有人知道具体原因 欢迎留言。
示例:
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Vue-upload-component Test</title>
- <script src="https://unpkg.com/vue"></script>
- <script src="https://unpkg.com/vue-upload-component"></script>
- </head>
- <body>
- <div id="app">
- <ul>
- <li v-for="file in files">{{file.name}} - Error: {{file.error}}, Success: {{file.success}}</li>
- </ul>
- <file-upload
- ref="upload"
- v-model="files"
- post-action="/post.method"
- put-action="/put.method"
- @input-file="inputFile"
- @input-filter="inputFilter"
- >
- 上传文件
- </file-upload>
- <button v-show="!$refs.upload || !$refs.upload.active" @click.prevent="$refs.upload.active = true" type="button">开始上传</button>
- <button v-show="$refs.upload && $refs.upload.active" @click.prevent="$refs.upload.active = false" type="button">停止上传</button>
- </div>
- <script>
- new Vue({
- el: '#app',
- data: function () {
- return {
- files: []
- }
- },
- components: {
- FileUpload: VueUploadComponent
- },
- methods: {
- /**
- * Has changed
- * @param Object|undefined newFile 只读
- * @param Object|undefined oldFile 只读
- * @return undefined
- */
- inputFile: function (newFile, oldFile) {
- if (newFile && oldFile && !newFile.active && oldFile.active) {
- // 获得相应数据
- console.log('response', newFile.response)
- if (newFile.xhr) {
- // 获得响应状态码
- console.log('status', newFile.xhr.status)
- }
- }
- },
- /**
- * Pretreatment
- * @param Object|undefined newFile 读写
- * @param Object|undefined oldFile 只读
- * @param Function prevent 阻止回调
- * @return undefined
- */
- inputFilter: function (newFile, oldFile, prevent) {
- if (newFile && !oldFile) {
- // 过滤不是图片后缀的文件
- if (!/\.(jpeg|jpe|jpg|gif|png|webp)$/i.test(newFile.name)) {
- return prevent()
- }
- }
- // 创建 blob 字段 用于图片预览
- newFile.blob = ''
- let URL = window.URL || window.webkitURL
- if (URL && URL.createObjectURL) {
- newFile.blob = URL.createObjectURL(newFile.file)
- }
- }
- }
- });
- </script>
- </body>
- </html>
详细文档查看网站。
vue项目内嵌入到app input type=file 坑(文件上传插件)的更多相关文章
- jquery的input:type=file实现文件上传
<!DOCTYPE html> <html> <head> <title>html5_2.html</title> <style> ...
- input type="file"多图片上传 原生html传递的数组集合
单个的input type="file"表单也是可以实现多图片上传的 代码如下: <form action="manypic.php" method=&q ...
- input type=file实现图片上传,预览以及图片删除
背景 前两天在做一个PC网站的意见反馈,其中涉及到了图片上传功能,要求可以上传多张图片,并且支持图片上传预览及图片删除, 图片上传这一块以前没怎么搞过,而且一般也很少会碰到这样的需求,所以在做这个功能 ...
- input type="file" accept="image/*"上传文件慢的问题解决办法
相信大家都写过<input type="file" name="file" class="element" accept=" ...
- input type=file实现图片上传
<label for="file"> <img src="images/morende.jpg" alt=""> & ...
- input type="file"多图片上传
单个的input type="file"表单也是可以实现多图片上传的 代码如下: <form action="manypic.php" method=&q ...
- Bootstrap文件上传插件File Input的使用
基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用 Bootstrap文件上传插件File Input是一个不错的文件上传控件, ...
- 获取input type=file 的文件内容(纯文本)
一.获取input type=file 的文件内容(纯文本) 1.需求一 通过点击其他事件,来触发 文件选择框(限定格式为 .c 文件),而不是手动鼠标点击触发. [思路:] step1:将 inpu ...
- 基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用
Bootstrap文件上传插件File Input是一个不错的文件上传控件,但是搜索使用到的案例不多,使用的时候,也是一步一个脚印一样摸着石头过河,这个控件在界面呈现上,叫我之前使用过的Uploadi ...
随机推荐
- [转]Opcode是啥以及如何使用好Opcache
转载链接:Opcode是啥以及如何使用好Opcache 啥是Opcode? 我们在日常的PHP开发过程中,应该经常会听见Opcache这个词,那么啥是Opcode呢? Opcache 的前生是 Opt ...
- 08 Json结构化Datetime时间以及保留中文
错误描述: import json import datetime a = datetime.datetime.now() print(a) b = json.dumps(a) print(b) 如上 ...
- Redis主从配置以及哨兵模式
Redis主从模式,应用写master,读slave,减轻master的压力. 配置主结点: daemonize yes port 6379bind 0.0.0.0 pidfile /opt/redi ...
- deep_learning_LSTM长短期记忆神经网络处理Mnist数据集
1.RNN(Recurrent Neural Network)循环神经网络模型 详见RNN循环神经网络:https://www.cnblogs.com/pinard/p/6509630.html 2. ...
- jQuery获取兄弟标签的文本
// 一个div里面有一个span标签和多个button标签,每个button标签都有id,span标签没有id,通过点击其中一个button标签,来获取到span标签的text function ( ...
- Java注解demo
# 为了熟悉了解注解,写的一个小demo# demo的主要功能是扫描一个class中的包含我们自定义注解的方法,然后把他们的返回值放到一个map中 public class QQ { public s ...
- win10上使用自带的Hyper-V安装虚拟机
Hyper-V管理器,新建虚拟机,安装了.iso系统,但启动报错,电脑上联想G40-70,都说在bios设置的security里开启硬件虚拟化选项,可我security里没有虚拟化相关选项, 后来在 ...
- STL源码阅读-functor与adapter
为什么要用仿函数 函数指针不灵活,难以与STL其他组件配合使用 Adapter 将一个class的接口转换为另一个class的接口,使原本因接口不兼容而不能合作的classes,可以一起运作 STL中 ...
- Centos7基础优化操作项
1.基础优化操作项:更新yum源信息第一个:就近使用yum源地址,安装软件更快.curl -s -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors. ...
- 对Spring Boot 及Mybatis简单应用
因为没有系统的学习过SpringBoot,在对照一个别人的SpringBoot项目,进行简单的搭建及使用. 1.首先创建SpringBoot项目之后,这里会有默认的启动类,基本不需要配置,在类的上边有 ...