In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to upload files in vue". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to upload files with vue"!
1. Use the el-upload plug-in of elementUI to upload.
Html:
Js:
Data () {return {AddSubmenuData: {id: ", pid:", funType:1, name: ", sort:", SystemCoding: ", remarks:", imageUrl:''},} }, methods: {/ / get picture information and convert it to base64 handleChange (file, fileList) {let reader = new FileReader (); let fileResult = ""; reader.readAsDataURL (file.raw); reader.onload = function () {fileResult = reader.result;}; reader.onloadend = function () {this.AddSubmenuData.imageUrl = fileResult} }}
Css:
/ deep/. Avatar-uploader. El-upload {border: 1px dashed # d9d9d9; border-radius: 6px; cursor: pointer; position: relative; overflow: hidden; margin-left: 80px; margin-bottom: 22px;} .avatar-uploader. El-upload:hover {border-color: # 409EFF;} .avatar-uploader-icon {font-size: 28px; color: # 8c939d Width: 178px; height: 178px; line-height: 178px; text-align: center;} .avatar {width: 178px; height: 178px; display: block;}
Effect picture:
2. Use input for upload.
1), html
First of all, the type attribute of input should be changed to file, if you need to click the button to upload the file. You can add a ref= "fileInput" to input, and then invoke the input event by clicking the button: @ click= "$refs.fileInput.click ()".
Add
2), js
After getting the file, you can process the data and call the interface. Because sometimes the uploaded file is duplicated, calling the method again is invalid, so you can clear the previously uploaded file after each upload, so that the method can be called repeatedly even if the file is the same. This.$refs.fileInput.value=''
/ / get file data getFile (event) {/ / this is the file you uploaded event.target.files [0] let formFile = new FormData (); formFile.append ("file", event.target.files [0]); formFile.append ("apply_info_id", this.RndNum (12)); formFile.append ("file_type",'') / / call interface file_upload (formFile) .then (res = > {this.addInformation.addPoupTableData.data.push ({name:res.data.name,id:res.data.id,size: (event.target.files [0] .size / 1024) .tofixed (0) + "kb", path:res.data.path}) / / clear the file this.$refs.fileInput.value=''} after calling the interface)} To this point I believe you have a deeper understanding of "how to upload files in vue". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.