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. Use CSS to draw a small pointed-corner chat di...
Table of contents 1. The significance of users an...
Vue data two-way binding principle, but this meth...
introduction: Slider drag verification is now use...
example: <html> <head> <style type...
After installing the latest Windows 10 update, I ...
Table of contents Preface Understanding a stack a...
Nexus provides RestApi, but some APIs still need ...
I am going to review Java these two days, so I wr...
<div id="root"> <h2>Keep go...
MySQL allows you to create multiple indexes on a ...
The implementation idea of the javascript game ...
Table of contents 1. Redux 1.1. Store (librarian)...
This article shares with you a draggable photo wa...
background Speaking of MySQL deadlock, I have wri...