Vue中文件上传

 使用饿了么组件进行文件上传代码的编写时,发现里面的demo都是直接上传,并没有先传到本页面,再点击按钮发送到指定服务器的例子

另外,如果直接使用样例的话,会很明显的发现,图片上传后,显示的缩略图会异常的慢!

所以打算自己编写,但是这样一来,就发现了问题,貌似无法拿到file对象

后来通过查找资料,发现了el-button的:on-change属性。

通过给:on-change属性指定事件,我们可以实现对上传的文件的操作

<el-upload
class="avatar-uploader"
action="https://jsonplaceholder.typicode.com/posts/"
:show-file-list="false"
:on-change="test"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload">
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
金麟岂是池中物,一遇风云便化龙!
原文地址:https://www.cnblogs.com/ABKing/p/12444203.html