前端调用路由导出数据方法记录

1.登录接口调用之后赋值token
  this.$cookie.set('token', data.token)
 
 2.this.$http.BASE_URL :配置的全局基础路由
封装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
 
3.导出的API:/api/ec/amo/sys/scheduling/anchor/export
方法:
 <el-button type="primary" @click="exportFun()">导出数据</el-button>
// 导出数据
      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)
      },
posted @ 2020-05-28 13:56  苏小白啊  阅读(763)  评论(0编辑  收藏  举报