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)
        })
    },
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容