axios的各种请求及传参


get请求数据

用params传参数是一个对象

//请求数据
    insuranceClassifyData () {
      this.$http.get(Apis.INSURANCE_CLASSIFY, {
        params: {
          pageNo: 1,
          sortBy: 'weight:desc'
        }
      })
        .then(resp => {
          if (resp.data.statu === 200 && resp.data.message === 'SUCCESS') {
            console.log(resp.data.data.list)
            this.classifyData = resp.data.data.list
          }
        })
        .catch(resp => {
          console.log(resp)
        })
    },

post和put上传数据

 /*
    * 表单提交事件/新建/修改
    * formName:要提交的那个表单的表单对象
    */
    submitClassifyForm (formName) {
      if (formName.cargoCategoryId) {
        this.$http.put(Apis.INSURANCE_CLASSIFY + `/${formName.cargoCategoryId}`, formName)
          .then(resp => {
            location.reload()  //成功以后刷新页面
          })
          .catch(resp => {
            console.log(resp)
          })
      } else {
        this.$http.post(Apis.INSURANCE_CLASSIFY, formName)
          .then(resp => {
            location.reload()
          })
          .catch(resp => {
            console.log(resp)
          })
      }
    },

delete删除数据

  // 删除事件
    deleteClassify (data) {
      this.$http.delete(Apis.INSURANCE_CLASSIFY + `/${data.cargoCategoryId}`)
        .then(resp => {
          location.reload()
        })
        .catch(resp => {
          console.log(resp)
        })
    },

转载:https://www.jianshu.com/p/445f0a712435


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM