欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

前端跨域请求axios里面withCredentials: true

程序员文章站 2022-06-16 10:12:44
项目中遇到的,举例://立即领取 receive(x) { let _this = this; jcLoading.open(); axios({ method: "post", url: apiConfig.getCoupon, withCredentials: true, data: { type: x }, //请求头配置...

项目中遇到的,举例:

//立即领取
    receive(x) {
      let _this = this;
      jcLoading.open();
      axios({
        method: "post",
        url: apiConfig.getCoupon,
        withCredentials: true,
        data: {
          type: x
        },
        //请求头配置
        headers: { p: _this.pValue },
        type: "json"
      })
        .then(res => {
          jcLoading.close();
          let resp = res.data;
          if (resp.code === 200) {
            // 200-领取成功
            jcAlert("领取成功");
          } else if (resp.code === 299) {
            // 299-未登录
            jcApp.login();
          } else {
            // jcToast(resp.message);
            jcAlert(resp.message || "网络繁忙请稍后再试~");
          }
        })
        .catch(e => {
          jcToast("网络繁忙请稍后再试");
        });
    },

 

本文地址:https://blog.csdn.net/weixin_38747509/article/details/110621644