In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the vue download document garbled how to solve the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this vue download document garbled how to solve the article will have a harvest, let's take a look at it.
Vue download document garbled
Recently write the function vue export, but do not know why, a request interface is garbled
Later, I wrote the sentence responseType: "blob" in the interface.
Be happy to open it as soon as you can download it, and there are garbled codes in the downloaded file.
Later, I kept thinking that I finally found a way.
It finally succeeded by adding a sentence to it!
I'll paste the code for everyone.
ExportAccountApi (data) .then (res= > {console.log ('777666 recording training res) const blob = new Blob ([res], {type: "application/vnd.ms-excel"}); let fileName = "Deposit record details .xls"; if ("download" in document.createElement ("a")) {const elink = document.createElement ("a"); elink.download = fileName Elink.style.display = "none"; elink.href = URL.createObjectURL (blob); document.body.appendChild (elink); elink.click (); URL.revokeObjectURL (elink.href); document.body.removeChild (elink);} else {navigator.msSaveBlob (blob.fileName)}) File download returns garbled processing vue+axios
The data stream returned from the backend is garbled, which can be solved by using the method of new Blob ().
The returned result of garbled code is as follows:
Solution async postClick () {const res = await axios ({url: 'backend interface', method: 'post', data: {id:' file id'} responseType: 'blob'}) const content = res.data const fileName =' a.png' / file name / / if the file type is uncertain Type can write the empty string const bolb = new Blob ([content]) {type:''}) if ('download' in document.createElement (' a')) {const link = document.createElement ('a') link.download = fileName link.style.display = 'none' / / URL.createObjectURL (bolb) = blob: http://localhost:8080/a34a8a20-acf2-3f21-bc22-45994d9f0290 link.href = URL.createObjectURL (bolb) document.body.appendChild (link) link.click () URL.revokeObjectURL (link.href) document.body.removeChild (link)}} this is the end of the article on "how to solve the garbled problem of vue download documents". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to solve the garbled vue download documents". If you still want to learn more knowledge, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.