zoukankan      html  css  js  c++  java
  • vue中axios复用封装

        ajax2: function() {
          let that = this;
          return that
            .$http({
              method: "get",
              url:
                "/Home/Verify/index?token=" + localStorage.getItem("manage_token")
            })
            .then(response => {
              //登录成功之后获取用户数据
              if (response.data.verify) {
                return that
                  .$http({
                    method: "post",
                    url: "/Home/Manage/request",
                    data: qs.stringify({
                      username: localStorage.getItem("manage_num"),
                      currentPage: that.currentPage + 1,
                      pageSize: 15,
                      status: that.screen_value, //筛选
                      keyword: that.search_value //搜索
                    })
                  })
                  .then(response => {
                    return response.data;
                  })
                  .catch(error => {
                    MessageBox("提示", "网络错误" + error.response.status);
                  });
              } else {
                //登录过期 => 清除前台存储的登录信息并返回登录页
                let instance = Toast("登录已失效,请重新登录!");
                setTimeout(() => {
                  instance.close();
                  localStorage.removeItem("manage_token");
                  localStorage.removeItem("manage_num");
                  that.$router.push({ path: "/pages/Login" });
                }, 1000);
              }
            })
            .catch(error => {
              MessageBox("提示", "网络错误" + error.response.status);
            });
        },

    调用

    that.ajax2().then(function(res) {
            if (res) {
              for (let i = 0; i < res.length; i++) {
                that.teaching_record.push(res[i]);
              }
              that.currentPage++;
              that.loading = false;
              Indicator.close();
            } else {
              that.loading = true;
              Indicator.close();
              that.bottom = true;
            }
          });
  • 相关阅读:
    Java之IO(一)InputStream和OutputStream
    bitset库
    assert
    C++ 与 Python 混合编程
    C++多线程
    C++11新特性
    C++性能优化指南
    C++随机数
    C++中struct与class的区别
    C++杂记
  • 原文地址:https://www.cnblogs.com/chenzeyongjsj/p/8883180.html
Copyright © 2011-2022 走看看