js导出数据为excel表

1.接口数据后端写,

2.代码如下:

 var params={
              "filters":[
              {"propertyCode":"sequenceNo",
              "propertyType":0,
              "propertyValue":"2021-123533",
              "propertyValueName":""}
              ],
              "mobile":false,
              "page":0,
              "queryCode":"KPSQ",
              "schemaCode":"KPSQ",
              "size":20,
              "columns":[]
              }
            debugger;

          this.$axios.post('/api/api/runtime/query/exportKp',params,{ responseType: "arraybuffer" }).then(res=>{
            debugger;
            const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });//把字节流转变为excel数据
            debugger;//断点

            const fileName = `sss.xlsx`;//excel表的名字
            debugger;
            const a = document.createElement('a');
            const url = URL.createObjectURL(blob);
            a.download = fileName;
            a.href = url;
            a.click();
            URL.revokeObjectURL(url);
              
          })

 

posted @ 2021-04-02 14:14  喜欢美食的利亚  阅读(165)  评论(0编辑  收藏  举报