vue下載文件以及文件重命名方式
vue下載文件及文件重命名
http Content-type對照表大家自行百度
/** * 下載文件以及文件重命名 * @param item 文件在數(shù)據(jù)庫中存儲信息 * @param that this別名 */ export function downFile(item, that) { // xxx是后臺接口, yyy是后臺需要的數(shù)據(jù) // {responseType: 'blob'}必須添加,否則下載的文件會出現(xiàn)亂碼 that.$axios.post('xxx', { yyy }, { responseType: 'blob' }).then(res = >{ if (res.status === '0') { let types = '' // 判斷文件類型,補充type if (item.file_type === 'xlsx' || item.file_type === 'xls') { types = 'application/vnd.ms-excel' } else if (item.file_type === 'png') { types = 'application/x-png' } else if (item.file_type === 'jpg') { types = 'application/x-jpg' } else if (item.file_type === 'jpeg') { types = 'image/jpeg' } // res.data是后臺返回的二進制數(shù)據(jù),type:types為下載的數(shù)據(jù)類型 const blob = new Blob([res.data], { type: types }) const downLoadEle = document.createElement('a') const href = URL.createObjectURL(blob) downLoadEle.href = href // ooo為自定義文件名 downLoadEle.download = 'ooo'document.body.appendChild(downLoadEle) downLoadEle.click() document.body.removeChild(downLoadEle) window.URL.revokeObjectURL(href) } }) }
頁面引用即可
import {downFile} from '.xx/xxx/xxx' click(item) { const that = this downFile(item, that) }
vue項目如何改名
在對應(yīng)的文件資源管理器中重命名到你想要更改的名字(比如這里從hello改成vuejs2)
把項目的node_modules文件夾刪除(就是刪掉你這個文件夾已有的依賴,別慌,過會可以重新下回來)
找到項目中的package.json文件,
然后重新加載一下依賴項,在對應(yīng)目錄的cmd輸入npm install
等依賴加載完后,項目就成功重命名了!!
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue.js 打包時出現(xiàn)空白頁和路徑錯誤問題及解決方法
這篇文章主要介紹了vue.js 打包時出現(xiàn)空白頁和路徑錯誤問題及解決方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06vue在install時node-sass@4.14.1?postinstall:node?scripts/buil
最近在npm install 的時候遇到了個問題,所以給大家總結(jié)下,下面這篇文章主要給大家介紹了關(guān)于vue在install時node-sass@4.14.1?postinstall:node?scripts/build.js錯誤的解決方法,需要的朋友可以參考下2023-05-05Element-ui樹形控件el-tree自定義增刪改和局部刷新及懶加載操作
這篇文章主要介紹了Element-ui樹形控件el-tree自定義增刪改和局部刷新及懶加載操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08