美文网首页
axios的各种请求及传参

axios的各种请求及传参

作者: chan_it | 来源:发表于2019-05-04 14:43 被阅读0次

    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)
            })
        },
    

    相关文章

      网友评论

          本文标题:axios的各种请求及传参

          本文链接:https://www.haomeiwen.com/subject/xsbxoqtx.html