• 前端如何使用post下载文件(将用户勾选的数据导出、下载),以及下载window.open是预览的文件


    【导出】功能分析,需要将用户勾选的数据已post的形式传给后端,后端返回给我们文件流

    一、使用原生

    1、设置原生encType(数据类型)、method(请求方式)、target等;

    1.action 规定当提交表单时向何处发送表单数据; —— URL
    2. enctype 规定在向服务器发送表单数据之前如何对其进行编码。(适用于 method=“post” 的情况);
    3. method 规定用于发送表单数据的 HTTP 方法;—— get、post
    4. target 规定在何处打开 action URL;—— _blank、_self、_parent、 _top

    2、设置原生的button按钮,type为submit;并在点击时,触发响应的事件;

    3、需要在form内写入一个隐藏的input标签,用于入参数据组织;

    <form action={
       '/hgzx-web/api/ydyjxxcx/excelExport?token=123'} encType="application/x-www-form-urlencoded" method="post" target="_blank">
        {
       /* { display: 'none' }} /> */}
        <Input name="skssqq" value={
       skssqq} style={
       {
       display: 'none'}}/>
        <Input name="skssqz" value={
       skssqz} style={
       {
       display: 'none'}}/>
        <Input name="jydszsf" value={
       formData.jydszsfDm} style={
       {
       display: 'none'}}/>
        <Input name="jydszxzqh" value={
       formData.jydszxzqhDm} style={
       {
       display: 'none'}}/>
        <Input name="zsxmDm" value={
       formData.zsxmDm} style={
       {
       display: 'none'}}/>
        <Row className="mb30 buttomList">
            <Button type="primary" className="ml20" onClick={
       () => {
       
                this.queryByDate()
            }}
            >查询</Button>
            <Button type="primary" className="ml20" 
                    onClick={
       (e) => this.exportExcel(e)} htmlType="submit"
                    disabled={
       dat
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

  • 相关阅读:
    VISUAL STUDIO调试器指南---断点和跟踪点
    Swift-24-集合对象
    佛山科学技术学院考研介绍
    一种新的数据聚类启发式优化方法——黑洞算法(基于Matlab代码实现)
    vue之$emit返回值
    网络安全(黑客)自学笔记1.0
    面试常问的异常体系
    JDK下载安装及环境配置
    数据存储和内存对齐
    vivado 仿真读写bmp图片
  • 原文地址:https://blog.csdn.net/weixin_45549481/article/details/128181571