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
Grid is a two-dimensional grid layout system. Wit...
In our daily business, form validation is a very ...
MySQL stored procedures, yes, look like very rare...
Table of contents Overview 1. Dependency Injectio...
Last time, a very studious fan asked if it was po...
Let's talk about the difference first last, t...
Table of contents Create an image File Structure ...
Table of contents 1. Docker distributed lnmp imag...
This article shares the mysql5.6.24 automatic ins...
need: Implement dynamic display of option values ...
a : Indicates the starting or destination positio...
mysql-5.7.20-winx64.zipInstallation package witho...
MySQL software installation and database basics a...
background As we all know, after we develop a Jav...
This is an article about website usability. The a...