当前位置:网站首页>Uploading pictures with FileReader object
Uploading pictures with FileReader object
2022-06-26 07:57:00 【Forge ahead and have a bright future】
Application scenarios —— To upload pictures
Native input , Set the size and transparency to 0, Other styles should be designed by yourself

html, Design according to the design drawing
<div >
<span>
<!-- plus -->
<img src="@static/images/icon/add_img.png" />
</span>
<span> To upload pictures </span>
<input @change="add_img" id="imgUpdateId" type="file" />
</div> How to add a new picture , Get file Collection to get the type of picture 、 name 、 size , Do some restrictions on uploading pictures ,
add_img(event) {
var reader = new FileReader();
var file = event.target.files[0];
const isJPG =
file.type == "image/jpeg" ||
file.type == "image/png" ||
file.type == "image/gif";
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isJPG) {
this.$message.error(" Uploading a picture of your head can only be JPG/PNG/GIF Format !");
return;
}
if (!isLt2M) {
this.$message.error(" The size of the uploaded image cannot exceed 2MB!");
return;
}
reader.readAsDataURL(file);
var that = this;
reader.onloadend = function() {
that.fileLists.push(file); // For reference file aggregate
that.imgs.push({ img_addr: reader.result }); // For display
};
}Remember to delete pictures document.getElementById("imgUpdateId").value = "" , Otherwise, you can't upload the picture you just deleted
in order to Better understand FileReader, Make a break and come in

Get file information

Get the picture information

边栏推荐
- 我想造SQL数据(存储结构)
- Exit of shell internal value command
- The 9th zero code training camp is officially open for registration! (Beijing, Shanghai, Guangzhou and Shenzhen)
- Database learning notes I
- Google Earth engine (GEE) 02 basic knowledge and learning resources
- [North Asia data recovery] a server data recovery method in which the partitions in the RAID5 array are formatted due to the misoperation of the NTFS file system
- Redis(4)----浅谈整数集合
- This article will take you to learn in detail what is FTTH
- Which securities company has the lowest Commission for opening a mobile account? Is it safe to open an account online?
- Baoyan postgraduate entrance examination interview - Network
猜你喜欢

Chapter II (summary)

Uniapp uses uviewui

Median segmentation (find rules) - Niuke

B站增量数据湖探索与实践

Ping An technology's practice of migrating from Oracle to ubisql

PyTorch-12 GAN、WGAN

I want to create SQL data (storage structure)

Okhttp3 source code explanation (IV) cache strategy, disadvantages of Android mixed development

Niuniu looks at the cloud (greedy, hash, push formula) - the first session of Niuke winter vacation training camp

Color code
随机推荐
Uniapp scrolling load (one page, multiple lists)
Orderly arrangement
解决 psycopg2.NotSupportedError: PQconninfo not available in libpq < 9.3
[UVM practice] Chapter 2: a simple UVM verification platform (5) build test cases
QT之一个UI里边多界面切换
手机开户哪个证券公司佣金最低?网上开户是否安全么?
我想造SQL数据(存储结构)
Class class of box selection four to and polygon box selection based on leaflet encapsulation
Uniapp wechat withdrawal (packaged as app)
CMDA 3634 image processing
Color code
Baoyan postgraduate entrance examination interview - Network
[UVM basics] connect of UVM_ Phase execution sequence
Which securities company has the lowest Commission for opening a mobile account? Is it safe to open an account online?
What is the difference between bone conduction earphones and ordinary earphones? Advantages of bone conduction earphones
JS event loop mechanism
The long path of Xiao Sha (graph theory, Euler diagram)
数据中心灾难恢复的重要参考指标:RTO和RPO
Flower instruction WP
Data governance: from top project to data culture!