当前位置:网站首页>Upload and modify the use of avatars
Upload and modify the use of avatars
2022-06-25 11:03:00 【Stranger & love sorrow】
Handwriting input Methods
1 Write the uploaded input Button
<input type='file' accept="image/*" @change='change'> Upload local file type type , Indicates that the file is uploaded input
accept Type of upload , Represents a picture
@change Trigger after the file is selected
2 Corresponding change event
change(e) {
// Handwritten input You need an object to convert the local image into the corresponding format to upload
let formData = new FormData();
// e.target.files Is an array of selected files
formData.append("file", e.target.files[0]);
// take formData This object is passed to the interface that modifies the avatar
updateImg(formData).then(res => {
if (res.code == 200) {
Toast(res.msg);
// res.data.path The URL returned is the avatar , It also depends on the returned data
this.userData.avatar = res.data.path;
// Some projects need to send the successful image to the website , Send and modify data interface , See the background processing for details
updateUser({ avatar: res.data.path });
}
});
},Corresponding input Change the style of
DOM structure
<a href="javascript:;" class="file"> Select File
<input type="file" name="" id="">
</a>css structure
.file {
position: relative;
display: inline-block;
background: #D0EEFF;
border: 1px solid #99D3F5;
border-radius: 4px;
padding: 4px 12px;
overflow: hidden;
color: #1E88C7;
text-decoration: none;
text-indent: 0;
line-height: 20px;
}
.file input {
position: absolute;
font-size: 100px;
right: 0;
top: 0;
opacity: 0;
}
.file:hover {
background: #AADFFD;
border-color: #78C3F3;
color: #004974;
text-decoration: none;
}The modified style is shown in the following figure

Click to see more specific style changes
vant Of Uploader Use of components
1 Use Here is the basic usage
<van-uploader :after-read="afterRead" />2 Upload files
methods: {
afterRead(file) {
// file It's the handwriting on it input in , after FromData The picture address after packaging , It can be uploaded directly to the server
updateImg(file).then(res => {
if (res.code == 200) {
Toast(res.msg);
// res.data.path The URL returned is the avatar , It also depends on the returned data
this.userData.avatar = res.data.path;
// Some projects need to send the successful image to the website , Send and modify data interface , It depends on whether it has been handled in the background
updateUser({ avatar: res.data.path });
}
},
},matters needing attention :
1 Handwriting input You need to use a FormData Object to convert the format , and vant Of file It's already converted
2 This converted format , It's an object , Directly treat the whole object as data Parameters can be passed , The specific situation depends on the project interface
3 After the transmission , The background will return data , Among them data.path Is the URL link of the modified avatar
4 Some projects are not processed in the background , We need to put this avatar website again , Pass to the interface for modifying user information , The purpose of modifying the Avatar has been achieved
elementUi Upload your avatar
<el-upload
:action="uploadURL" // Address or interface for uploading pictures , Full web address required
// Trigger when you click the uploaded file in the file list , With a parameter , There are http Picture format for , You can preview pictures
:on-preview="handlePreview"
// Trigger... When deleting files , With a parameter , There are http Picture format for
:on-remove="handleRemove"
// Set the request header file when uploading , Because some pictures need to be uploaded token, You can set it up here
:headers="headerObj"
// Type of file list
list-type="picture"
// Triggered when the file is uploaded successfully , There will also be parameters , You can find pictures in the corresponding format
:on-success="handleSuccess"
>Be careful :
In every event , Will come with a parameter , You can find pictures in two formats ,https The Internet Format and "tmp_uploads\468f50432ed8b67b89e2490dc9e7f34d.jpg" Local Format , Which format of pictures will be uploaded at that time , See the requirements of the interface document
If you want to preview the picture , The bullet box needs to be written by yourself , Can be in on-preview In the incident , Get the network format of the currently clicked picture
Because the image upload interface or website here is an independent website ,action attribute Value , Must be a complete web address
headers Attributes are used to pass token Of , The specific format depends on the project requirements
边栏推荐
- Five types of questions about network planning
- Tutorial on installing SSL certificates in Microsoft Exchange Server 2007
- 每日3題(3)-檢查整數及其兩倍數是否存在
- [dynamic planning] - Digital triangle
- 2022年PMP项目管理考试敏捷知识点(2)
- Handling of NPM I installation problems
- 西门子PLCS7-200使用(一)---开发环境和组态软件入门
- 中国信通院沈滢:字体开源协议——OFL V1.1介绍及合规要点分析
- Floating window --- create a system floating window (can be dragged)
- Oracle query comes with JDK version
猜你喜欢

Garbage collection mechanism

MCU development -- face recognition application based on esp32-cam

Detailed explanation of Android interview notes handler

Network remote access using raspberry pie

报名开启|飞桨黑客马拉松第三期如约而至,久等啦

我的作文题目是——《我的区长父亲》

Handler asynchronous message processing

Technical practice and development trend of video conference all in one machine

Unreal Engine graphics and text notes: use VAT (vertex animation texture) to make Houdini end on Houdini special effect (ue4/ue5)

Advanced single chip microcomputer -- development of PCB (2)
随机推荐
Shen Ying, China Academy of communications and communications: font open source protocol -- Introduction to ofl v1.1 and analysis of key points of compliance
ES 学习
Shen Lu, China Communications Institute: police open source Protocol - ofl v1.1 Introduction and Compliance Analysis
学会自学【学会学习本身,比学什么都重要】
服务端渲染
16 种企业架构策略
性能之网络篇
Opencv learning (I) -- environment building
[200 opencv routines] 210 Are there so many holes in drawing a straight line?
Nuxtjs actual combat case
OpenCV学习(一)---环境搭建
【系统分析师之路】第六章 复盘需求工程(综合知识概念)
CSRF attack
网络协议学习---LLDP协议学习
Think about it
Kotlin implements a simple login page
成长:如何深度思考与学习
Tutorial on installing SSL certificates in Microsoft Exchange Server 2007
1-7Vmware中的快照与克隆
有关计网的五种类型题