In Vue, we generally have front-end and back-end separation projects, that is, we need to use tools such as axios to send requests to the background to implement data operations. 1. For example, when uploading pictures, the backend needs to transfer formData type data from the frontend <el-button type="primary" @click="uploadFile2()">Click to upload</el-button> <input type="file" @change="fileValueChange2()" ref="uploadFile2" enctype="multipart/form-data" style="display:none;" accept="image/jpeg,image/png,image/gif"> We use native input to achieve this. uploadFile2(){ // This event is triggered when the button is clicked // The function is to open the file upload pop-up box this.$refs.uploadFile2.click() }, fileValueChange2(){ // After selecting the file, the input change event will be triggered, and this function will be entered var formData = new FormData() // this.$refs.uploadFile2 is the method for getting DOM elements in Vue // All uploaded files can be obtained through files. If there are multiple files, formData.append('file',this.$refs.uploadFile2.files[0]) // Request type must be set formData.append('type', "head"); // If you need to pass the id, refer to the following code formData.append('id', this.id); // After configuration is complete, you only need to pass the formData variable to the backend insertNavigationUpload(formData).then(res=>{ console.log('Is it simple? My friend') }) },
export const tMessageNotification = data =>{ return request({ url:'/tMessageNotification/upload', method: 'POST', data, headers: {'Content-Type': 'application/json'}, }) } This is the end of this article about Vue using formData format type to upload files. For more relevant Vue file upload content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed process of building mysql5.7.29 on centos7 of linux
>>: Should I use distinct or group by to remove duplicates in MySQL?
1. Introduction Earlier we introduced the rapid d...
Suppose a user management system where each perso...
Demand background The team has the need for integ...
1. Mirror images disappear in 50 and 93 [root@h50...
Preface When developing static pages, such as Vue...
Table of contents What is FormData? A practical e...
1. Tools We need two tools now: MySQL server (mys...
First, pull the image (or just create a container...
Recently I saw a barrage effect on B station call...
Table of contents Preface: 1. Create a project wi...
1. Problem Multiple floating elements cannot expa...
The operating environment of this tutorial: Windo...
Table of contents 1. Enter a directory and create...
Description: Set a timer to replace the content of...
SQL statement DROP TRIGGER IF EXISTS sys_menu_edi...