首页 > 移动平台 > 详细

axios之前端发送get与post请求模板

时间:2019-11-30 20:23:59      阅读:154      评论:0      收藏:0      [点我收藏+]

import axios from "axios";

一、get

mounted() {
    axios
      .get(
        "/api/queryusertree?domId=" + this.domId + "&ownerId=" + this.ownerId,
        {
          headers: { Validate: "123456" }
        }
      )
      .then(response => {
        let object = response.data.data;
        let head = object;
        this.data = object.childList;
        console.log(this.data);
      })
      .catch(error => {
        console.log(error);
        alert("网络错误,不能访问");
      });
  },

 二、post

remove(userId) {
      let data = {
        domId: this.domId,
        ownerId: this.ownerId,
        userId: userId
      };//post传递对象到后台

      axios
        .post("/api/removedomuser", data, {
          headers: {
            //头部信息
            "Content-Type": "application/json;charset=utf-8",
            Validate: "123456" 
          }
        })
        .then(response => {
          let resultUtils = response.data;
          console.log(resultUtils);
        })
        .catch(error => {
          console.log(error);
          alert("网络错误,不能访问");
        });
    },

 

axios之前端发送get与post请求模板

原文:https://www.cnblogs.com/yanl55555/p/11963743.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!