满口金牙 2021-10-20 00:00 采纳率: 91.5%
浏览 74
已结题

Vue axios 我的ur l写法很low, 自已都看的不舒服, 还有什么写法,


  async search (event) {
      // 声明url变量
      let url = ''
      // 根据调用本方法Html元素 的ID,来选择发送axios请求的 url地址, (区分,初始页,上一页或者下一页的 url地址)
      if (event.target.id === 'previous') {
        url = this.previous
      } else if (event.target.id === 'next') {
        url = this.next
      } else {
        // 下面的写法可能用,但感觉很难受,有其它写法吗??--------------------------------------------------------------
        url = 'group/?project_name=' + this.inputProjectName + '&sample_name=' +
        this.inputSampleName + '&orderdate_gte=' + this.inputDateGte + '&orderdate_ite=' + this.inputDateIte + '&offset=' + 0
      }
      // 向后后端发送get请求,并返回数据对象 res
      const { data: res } = await this.$http.get(url)
  • 写回答

4条回答 默认 最新

  • 李筱宝 2021-10-20 09:13
    关注
    var a = {
        previous:this.previous,
        next:this.next,
    }
    
    const { data: res } = await this.$http.get(a[event.target.id] || "/group", { params: a[event.target.id] ? {} : {
        project_name: this.inputProjectName,
      sample_name: this.inputSampleName,
      orderdate_gte: this.inputDateGte,
      orderdate_ite: this.inputDateIte,
      offset: 0,
    })
    

    有用望采纳

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月20日
  • 已采纳回答 10月20日
  • 创建了问题 10月20日

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制