鍍金池/ 問(wèn)答/C++  HTML/ post請(qǐng)求下載excel文檔

post請(qǐng)求下載excel文檔

如圖,在postman中能實(shí)現(xiàn)下載,那js中應(yīng)該怎么實(shí)現(xiàn)呢,目前項(xiàng)目vue.js
圖片描述

回答
編輯回答
脾氣硬

這是Angular的:

$http({
    url: "",
    method: 'POST',
    timeout: 60000,
    headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=utf8'},
    transformRequest: function(obj) {
        var str = [];
        for(var p in obj)
            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
        return str.join("&");
    },
    data:{}
}).success(function (data) {
    var blob = new Blob([data], {type: "application/vnd.ms-excel;charset=utf-8"}),
        Temp = document.createElement("a");

    Temp.href = window.URL.createObjectURL(blob);
    Temp.download = "XXX.xlsx";
    angular.element('body').append(Temp);
    Temp.click();
});
2018年3月14日 18:54