zoukankan      html  css  js  c++  java
  • vue中Excel导出(后端传的值不同,前端导出方式不同)

    导出1:
    <Button class="mr10" type="primary" @click="exportSampleStockExcel()" :disabled="exportSampleStockExcel">导出</Button>
     
     
     exportSampleStockExcel(){
            this.$axios({
              url:'/sampleStock/exportSampleStockExcel',
              method:'get',
              responseType:'blob',
              params: {
              pageNum: this.pageParam.pageNum,
              pageSize: this.pageParam.pageSize,
            }
            }).then((data)=>{
              const url = window.URL.createObjectURL(data.data)
              const a = document.createElement('a')
              a.href = url
              a.download = '样衣列表.xls'
              document.body.appendChild(a)
              a.click()
              window.URL.revokeObjectURL(url)
              document.body.removeChild(a)
            }).catch(err => {
            reject('接口请求错误')
          })
          }
     
    导出2:
    <Button @click="exportData">导出</Button>
     
     
     // 导出
                exportData() {
                    this.$Loading.start();//显示进度条
                    this.$axios({
                        url: `/chenfan_sample/sampleStockin/stockinExport`,
                        method: 'get',
                        responseType: 'blob',
                        params: {
                            sampleStockinCode: this.formInline.sampleStockinCode,
                            sampleDressFileCode: this.formInline.sampleDressFileCode,
                        }
                    }).then((data) => {
                        const blob = new Blob([data], { type: 'text/plain;charset=utf-8' })
                        const url = window.URL.createObjectURL(blob)
                        const a = document.createElement('a')
                        a.href = url
                        a.download = '样衣入库单.xlsx'
                        document.body.appendChild(a)
                        a.click()
                        window.URL.revokeObjectURL(url)
                        document.body.removeChild(a)
                        this.$Loading.finish();//结束进度条
                    })
                },
    导出3:通过路由直接导出前端不需要做其它操作,记得加上token,token是根据登录接口获取到的,然后暴露在全局调用。this.$http.BASE_URL是基础请求路径,也是暴露为全局可以使用的。/api/ec/amo/sys/scheduling/anchor/export是get请求的导出接口
    封装ajax的页面:
    // 跨域请求,允许保存cookie
    axios.defaults.withCredentials = true
    axios.defaults.headers = {'Content-Type': 'application/json; charset=utf-8'}
    // 非生产环境 && 开启代理, 接口前缀统一使用空''前缀做代理拦截!
    const BASE_URL = process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/api' : window.SITE_CONFIG.baseUrl
    // 对面暴露的基础请求路径
    axios.BASE_URL = BASE_URL
     
     
     // 导出数据
          exportFun() {
            let exporthref = this.$http.BASE_URL + `/api/ec/amo/sys/scheduling/anchor/export?order=${this.searchForm.order}&liveStatus=${this.searchForm.liveStatus}&brandId=${this.searchForm.brandId}&token=${this.$cookie.get('token')}`
            window.open(exporthref)
          },
  • 相关阅读:
    input清楚阴影 number属性
    转 溢出隐藏
    多行,溢出隐藏 css
    JS判断移动端还是PC端(改造自腾讯网) 仅用于宣传动画,下载页等
    项目开发(Require + E.js)
    showPrompt弹框提示
    图形验证码
    CSS常用技术总结!~~
    移动开发常用技术总结!~~
    JavaScript常用技术总结!~~
  • 原文地址:https://www.cnblogs.com/wssdx/p/11481767.html
Copyright © 2011-2022 走看看