<template>
<div class="vue-upload-img-multiple">
<div v-if="images.length >0">
<ul>
<li v-for="image in images">
<img :src="data:image" @click='delImage($index)' />
<a href="#" style="position: absolute;" @click='delImage($index)'>
<span class="glyphicon glyphicon-remove"></span>
</a>
</li>
</ul>
<button @click="removeImage">移除全部图片</button>
<button @click='addPic' >上传</button>
</div> <div>
<div v-if="!image">
<h2>Select an image</h2>
<input type="file" @change="onFileChange">
</div>
<div v-else>
<img :src="data:image" />
<button @click="removeImage">Remove image</button>
</div>
</div> </div>
</template> <script>
export default {
name: 'Upload',
data: function () {
return {
images: []
}
},
methods: {
test () {
var vm = this
console.log(vm.message)
},
addPic () {
$('input[type=file]').trigger('click')
return false
},
onFileChange (e) {
var files = e.target.files || e.dataTransfer.files
if (!files.length) return
this.createImage(files)
},
createImage (file) {
var vm = this
var reader = null
var leng = file.length
for (var i = 0; i < leng; i++) {
reader = new window.FileReader()
reader.readAsDataURL(file[i])
reader.onload = function (e) {
vm.images.push(e.target.result)
}
}
},
removeImage: function (e) {
this.images = []
},
delImage: function (index) {
this.images.shift(index)
}
}
}
</script> <style lang="scss">
h1, h2 {
font-weight: normal;
} ul {
list-style-type: none;
padding: 0;
} li {
display: inline-block;
margin: 0 10px;
} a {
color: #42b983;
}
.vue-upload-img-multiple{
border:1px red solid;
}
</style>

vue2 上传图片的更多相关文章

  1. vue2上传图片到OSS

    第一步:安装阿里云OSS <!-- 引入在线资源 --> <script src="http://gosspublic.alicdn.com/aliyun-oss-sdk- ...

  2. h5 录音 自动生成proto Js语句 UglifyJS-- 对你的js做了什么 【原码笔记】-- protobuf.js 与 Long.js 【微信开发】-- 发送模板消息 能编程与会编程 vue2入坑随记(二) -- 自定义动态组件 微信上传图片

    得益于前辈的分享,做了一个h5录音的demo.效果图如下: 点击开始录音会先弹出确认框: 首次确认允许后,再次录音不需要再确认,但如果用户点击禁止,则无法录音: 点击发送 将录音内容发送到对话框中.点 ...

  3. vue2.0集成百度UE编辑器,上传图片报错!!!

    我这边配置进去之后,界面加载,文本输入都没有问题,就是上传图片会有问题 这张图, 左边红色框框 就是目录结构咯, 右边红色框框 就是各种网上教程给出的第一个路径配置对吧, 下面的就是绿色 服务器接口配 ...

  4. Vue2 全家桶仿 微信App 项目,支持多人在线聊天和机器人聊天

    前言 这个项目是利用工作之余写的一个模仿微信app的单页面应用,整个项目包含27个页面,涉及实时群聊,机器人聊天,同学录,朋友圈等等,后续页面还是开发中.写这个项目主要目的是练习和熟悉vue和vuex ...

  5. vue-axios配置token,上传图片

    vue1.0用 vue-resource 目前不维护了 vue2.0用 axios 使用 1.安装axios, npm install axios 2.在main.js中配置 import axios ...

  6. Vue2 后台管理系统解决方案

    基于Vue.js 2.x系列 + Element UI 的后台管理系统解决方案. github地址:https://github.com/lin-xin/manage-system demo地址:ht ...

  7. Vue2.0结合webuploader实现文件分片上传

    Vue项目中遇到了大文件分片上传的问题,之前用过webuploader,索性就把Vue2.0与webuploader结合起来使用,封装了一个vue的上传组件,使用起来也比较舒爽. 上传就上传吧,为什么 ...

  8. CKEditor5 + vue2.0 自定义图片上传、highlight、字体等用法

    因业务需求,要在 vue2.0 的项目里使用富文本编辑器,经过调研多个编辑器,CKEditor5 支持 vue,遂采用.因 CKEditor5 文档比较少,此处记录下引用和一些基本用法. CKEdit ...

  9. vue2.0路由-路由嵌套

    vue一个重要的方面就是路由,下面是自己写的一个路由的例子: 1.引入依赖库就不必再说 2.创建组件 两种写法 第一种:间接 <template id="home"> ...

随机推荐

  1. SpringMVC学习笔记(三)

    一.SpringMVC使用注解完成 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 <!--configure the setti ...

  2. MongoDB的基础知识

    本人只是软件开发的一个菜鸟,在学习MongoDB,总结了一点自己学习的知识,监督自己学习. 如果文章中有不足的地方,还请大神指点迷津,纠正改错,谢谢. 一.MongoDB简介 MongoDB是一个基于 ...

  3. python学习心得第五章

    python学习心得第五章 1.冒泡排序: 冒泡是一种基础的算法,通过这算法可以将一堆值进行有效的排列,可以是从大到小,可以从小到大,条件是任意给出的. 冒泡的原理: 将需要比较的数(n个)有序的两个 ...

  4. seaJS循环依赖的解决原理

    seajs模块的六个状态. var STATUS = {  'FETCHING': 1, // The module file is fetching now. 模块正在下载中  'FETCHED': ...

  5. java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ProgressBar$SavedState

    java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.Progress ...

  6. libsvm 训练后的模型参数讲解(转)

    主要就是讲解利用libsvm-mat工具箱建立分类(回归模型)后,得到的模型model里面参数的意义都是神马?以及如果通过model得到相应模型的表达式,这里主要以分类问题为例子.测试数据使用的是li ...

  7. linux 定时执行php脚本

    第一种方法: 1.编写shell脚本: shell文件:/home/www/shell/phpshell.php #!/bin/bash while [ true ]; do /bin/sleep 1 ...

  8. ubuntu远程桌面连接windows系统(转)

    现在用ubuntu系统,公司买了个windows的服务器,需要给配置一套环境,来回跑很麻烦,就想windows下可以的远程桌面,linux应该也有. 现在自己的ubuntu13.10,无法进入桌面的& ...

  9. Libcurl多线程crash问题(cento)

    cento :http://blog.csdn.net/delphiwcdj/article/details/18284429 1 问题背景 后台系统有一个单线程的http接口,为了提高并发处理能力, ...

  10. poj 1384 Piggy-Bank(完全背包)

    Piggy-Bank Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10830   Accepted: 5275 Descr ...