1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
      vueelement中axios如何下載文件

      這篇文章給大家分享的是有關(guān)vue element中axios如何下載文件的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

      成都創(chuàng)新互聯(lián)是專業(yè)的善左網(wǎng)站建設(shè)公司,善左接單;提供成都網(wǎng)站建設(shè)、成都網(wǎng)站制作,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行善左網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

      ?axios 接受文件流,需要設(shè)置 {responseType:'arraybuffer'}

      axios.post(
        apiUrl,
        formdata, 
        {responseType:'arraybuffer'}
      ).then(res=> {
        if (res.status === 200) {
         let blob = new Blob([res.data], {
          type: res.headers['content-type']
          });
      
          const fileName = res.headers['content-disposition'];
         const title = fileName && (fileName.indexOf('filename=') !== -1) ? fileName.split('=')[1] : 'download';
      
          require('script-loader!file-saver');
         saveAs(blob, title);
      } 
      })
      .catch();

      注: axios 中 response 表示服務(wù)器響應(yīng)的數(shù)據(jù)類型,可以是 arraybuffer , blob, document , json , text , stream . 默認(rèn)為: json

      ?后端發(fā)送文件:Python

      from flask import send_from_directory
      @admin_bp.route('/tasksothers/download', methods=["GET", "POST"])
      @auth.login_required
      def api_tasksothers_download():
          root_path = ''
          src_name = "a.sql"
          upload_path = os.path.join(root_path, src_name)
          print("upload_path =", upload_path)
          if os.path.isfile(upload_path):
            response = send_from_directory(root_path, src_name, as_attachment=True)
            print("response: ",response)
      
            response.headers["Access-Control-Expose-Headers"] = "Content-disposition"
            print("response: ", response.headers)
            return response

      注: 如果 response.header 中沒有添加  Access-Control-Expose-Headers 這個(gè)參數(shù)(代表:服務(wù)器允許瀏覽器訪問的頭(headers)的白名單),vue中就無法獲取 content-disposition,即 res.headers['content-disposition'];無法找到

      感謝各位的閱讀!關(guān)于“vue element中axios如何下載文件”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!


      當(dāng)前名稱:vueelement中axios如何下載文件
      網(wǎng)頁路徑:http://www.ef60e0e.cn/article/iijhhd.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        云安县| 翁源县| 克什克腾旗| 广平县| 社会| 怀远县| 绵阳市| 阜城县| 阿荣旗| 菏泽市| 黄梅县| 彰化市| 西丰县| 永丰县| 阿拉善盟| 大悟县| 福海县| 谢通门县| 沾益县| 承德县| 凯里市| 哈密市| 介休市| 什邡市| 墨脱县| 神农架林区| 卢湾区| 滨州市| 通化市| 德令哈市| 民和| 普定县| 福清市| 微博| 烟台市| 兴义市| 鹤山市| 阿拉善左旗| 五指山市| 望城县| 玛纳斯县|