This article shares the Vant Uploader component for uploading one or more pictures for your reference. The specific content is as follows HTML part <template> <div class="contWrap"> <van-uploader v-model="fileList" :multiple="true" :before-read="beforeRead" :after-read="afterRead" :before-delete="delUploadImg" upload-icon="plus" > <!-- Note: This is a custom upload style--> <!-- <p> <van-icon name="plus" color="#07c160" size=".5rem" /> Upload photo</p> --> </van-uploader> </div> </template> js part <script> import axios from "axios"; export default { name: "uploadImages", data() { return { fileList: [], uploadUrl: "/api/upload/fileUpload", headers: { token: this.$store.state.account.token, }, }; }, methods: { // Return Boolean value beforeRead(file) { if (file instanceof Array) { //Judge whether it is an array file.forEach((v) => { this.checkFile(v); }); } else { this.checkFile(file); } return true; }, //Image type checkcheckFile(file) { const format = ["jpg", "png", "jpeg"]; const index = file.name.lastIndexOf("."); const finalName = file.name.substr(index + 1); if (!format.includes(finalName.toLowerCase())) { Toast("Please upload" + format.join(",") + "Format picture"); return false; } }, afterRead(file) { // You can upload the file to the server by yourself at this time if (file instanceof Array) { file.map((v) => { v.status = "uploading"; v.message = "Uploading..."; this.uploadImg(v); }); } else { file.status = "uploading"; file.message = "Uploading..."; this.uploadImg(file); } }, //Upload uploadImg(file) { const formData = new FormData(); formData.append("file", file.file); axios .post(this.uploadUrl, formData, { headers: this.headers, }) .then((res) => { if (res.data) { if (file instanceof Array) { //Judge whether it is an array file.map((v, i) => { v.status = "success"; v.message = ""; v.url = res.data[i]; }); } else { file.status = "success"; file.message = ""; file.url = res.data.uploadUrl; } } }) .catch((err) => { this.$notify({ type: "warning", message: "Upload failed", }); }); }, //delete delUploadImg(item) { this.fileList = this.fileList.filter((v) => v.url != item.url); } }, }; </script> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to create a view in MySQL
>>: Steps for restoring a single MySQL table
Table of contents Install Software Management Ano...
You can go to the Ubuntu official website to down...
There are very complex HTML structures in web pag...
CSS Styles html,body{ width: 100%; height: 100%; ...
Div basic layout <div class="main"&g...
Table of contents nextTick v-model syntax sugar ....
Table of contents 1. Problem Description 2. Probl...
1. To develop web responsively, the page must ada...
1. Create a centos7.6 system and optimize the sys...
The rewrite module is the ngx_http_rewrite_module...
Data backup and restore part 3, details are as fo...
Variables defined in SASS, the value set later wi...
In the previous article, we have implemented loca...
This article uses vue, and adds mouse click event...
Import and export of Docker images This article i...