axios(post方法) + vue 方法导出excel文件(已解决导出乱码问题)

仅附上前台代码,

axios({

              method:'post',

              url: 'http://120.55.173.161:8088/api/business/ctl/webQueryOrderList',//测试

              data: qs.stringify(this.paramsOrder),

              headers: {

                  'Content-type': 'application/x-www-form-urlencoded'

              },

              responseType: 'blob',

            }).then((response)=>{

              this.doExportExecl(response, '订单导出.xls')

            });

doExportExecl(response, names) {

            if (!response) {

                return

                 }

            const isIE = !!window.ActiveXObject || 'ActiveXObject' in window // 判断是否是ie

            if (isIE) { // ie10+下载

              navigator.msSaveBlob(new Blob([response.data]), names)

            } else {

              var url = window.URL.createObjectURL(new Blob([response.data]), { type: 'application/vnd.ms-excel;charset=utf-8' })

              var link = document.createElement('a')

              link.style.display = 'none'

              link.href = url

              link.setAttribute('download', names)

              document.body.appendChild(link)

              link.click()

              URL.revokeObjectURL(link.href)

              document.body.removeChild(link)

            }

          },

你可能感兴趣的:(前端)