{"id":474,"date":"2023-05-07T10:40:53","date_gmt":"2023-05-07T02:40:53","guid":{"rendered":"http:\/\/yusemo.com\/?p=474"},"modified":"2023-05-07T10:40:53","modified_gmt":"2023-05-07T02:40:53","slug":"vuepost%e8%af%b7%e6%b1%82%e5%af%bc%e5%87%baexcel","status":"publish","type":"post","link":"https:\/\/yusemo.com\/?p=474","title":{"rendered":"vue+post\u8bf7\u6c42\u5bfc\u51faexcel"},"content":{"rendered":"<p>\u6700\u8fd1\u6709\u4e9b\u5947\u5947\u602a\u602a\u7684\u9700\u6c42\u3002\u6bd4\u5982\u540e\u7aef\u6ca1\u8bfb\u6cd5\u53d6\u670d\u52a1\u5668\u6743\u9650\u56e0\u6b64\u6ca1\u6cd5\u505a\u5230\u6587\u4ef6\u5bfc\u51fa\u6216\u8005\u5229\u7528oss\u5bfc\u51fa(\u516c\u53f8\u6ca1\u94b1)\u3002\u5bfc\u81f4\u5bfc\u51fa\u7684\u65f6\u4f20\u6587\u4ef6\u6d41\u7ed9\u524d\u7aef\u8ba9\u524d\u7aef\u83b7\u53d6\u3002\u6700\u5947\u602a\u662f\u5c45\u7136\u4e0d\u7528get\u7528post\u8bf4\u662f\u6587\u4ef6\u8fc7\u5927\u6015\u524d\u7aef\u63a5\u6536\u4e0d\u5168\u3002\u3002\u8fd9\u4ec0\u4e48\u626f\u6de1\u73a9\u610f\u3002\u3002get\u53ea\u662f\u6d4f\u89c8\u5668\u5bf9url\u957f\u5ea6\u505a\u4e86\u9650\u5236\u7f62\u4e86\u3002<br \/>\n\u7b97\u4e86\u9047\u5230\u8fd9\u4e48\u5f31\u7684\u540e\u7aef\u4f60\u53ea\u80fd\u914d\u5408\u6ca1\u6cd5\u5b50\u3002\u552f\u4e00\u7528blob\u7684\u597d\u5904\u5c31\u662f\u9632\u6b62\u76d7\u94fe\u548c\u53ef\u4ee5\u52a0\u5bc6\u3002\u81ea\u6211\u5b89\u6170\u5427\u3002<br \/>\n\u56e0\u6b64\u4ea7\u751f\u4e86\u5982\u4f55\u5728\u5c01\u88c5\u4e86http\u8bf7\u6c42\u91cc\u9762\u5229\u7528axios\u83b7\u53d6\u6587\u4ef6\u6d41\u5bfc\u51faexcel\uff1f<br \/>\n\u4e0b\u9762\u4e0a\u4ee3\u7801<br \/>\n<strong>\u91cd\u70b9\uff1aresponseType: &#8216;blob&#8217;<\/strong><\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/><\/div><\/td><td><div class=\"text codecolorer\">const axiosReq = (url, params) =&gt; {<br \/>\n&nbsp; axios<br \/>\n&nbsp; &nbsp; .post(url, params, {<br \/>\n&nbsp; &nbsp; &nbsp; responseType: &quot;blob&quot;,<br \/>\n&nbsp; &nbsp; &nbsp; headers: { &quot;Content-Type&quot;: &quot;application\/json&quot; }<br \/>\n&nbsp; &nbsp; })<br \/>\n&nbsp; &nbsp; .then(res =&gt; {<br \/>\n&nbsp; &nbsp; &nbsp; console.log(res, &quot;axios&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; const blob = new Blob([res.data], {<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; type: &quot;application\/zip;&quot;<br \/>\n&nbsp; &nbsp; &nbsp; });<br \/>\n&nbsp; &nbsp; &nbsp; const downloadElement = document.createElement(&quot;a&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; const href = window.URL.createObjectURL(blob);<br \/>\n&nbsp; &nbsp; &nbsp; const filename = res.headers[&quot;content-disposition&quot;]<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; .split(&quot;;&quot;)[1]<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; .split(&quot;=&quot;)[1]; \/\/filename;<br \/>\n&nbsp; &nbsp; &nbsp; downloadElement.href = href;<br \/>\n&nbsp; &nbsp; &nbsp; downloadElement.download = filename; \/\/\u547d\u540d\u4e0b\u8f7d\u540d\u79f0<br \/>\n&nbsp; &nbsp; &nbsp; downloadElement.click();<br \/>\n&nbsp; &nbsp; &nbsp; window.URL.revokeObjectURL(href); \/\/\u4e0b\u8f7d\u5b8c\u6210\u8fdb\u884c\u91ca\u653e<br \/>\n&nbsp; &nbsp; })<br \/>\n&nbsp; &nbsp; .catch(e =&gt; {<br \/>\n&nbsp; &nbsp; &nbsp; ElMessage.error(e.message);<br \/>\n&nbsp; &nbsp; });<br \/>\n};<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u6709\u4e9b\u5947\u5947\u602a\u602a\u7684\u9700\u6c42\u3002\u6bd4\u5982\u540e\u7aef\u6ca1\u8bfb\u6cd5\u53d6\u670d\u52a1\u5668\u6743\u9650\u56e0\u6b64\u6ca1\u6cd5\u505a\u5230\u6587\u4ef6\u5bfc\u51fa\u6216\u8005\u5229\u7528oss\u5bfc\u51fa(\u516c\u53f8\u6ca1\u94b1)\u3002\u5bfc\u81f4\u5bfc\u51fa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,38],"tags":[],"_links":{"self":[{"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/474"}],"collection":[{"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474"}],"version-history":[{"count":2,"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions"}],"predecessor-version":[{"id":476,"href":"https:\/\/yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions\/476"}],"wp:attachment":[{"href":"https:\/\/yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}