zoukankan      html  css  js  c++  java
  • React后台管理系统-ajax请求封装

    React后台管理系统-ajax请求封装

    1.新建文件夹 util , 在util里边新建 mm.jsx文件

    2.使用jquery里边的ajax发送请求,回调用promise,返回一个promise对象

    1. request(param){
    2.         return new Promise((resolve, reject) => {
    3.             $.ajax({
    4.                 type : param.type || 'get',
    5.                 url : param.url || '',
    6.                 dataType : param.dataType || 'json',
    7.                 data : param.data || null,
    8.                 success : res => {
    9.                     // 数据请求成功
    10.                     if(0 === res.status){
    11.                         typeof resolve === 'function' && resolve(res.data, res.msg);
    12.                     }
    13.                     // 没有登录状态,强制登录
    14.                     else if(10 === res.status){
    15.                         this.doLogin();
    16.                     }
    17.                     else{
    18.                         typeof reject === 'function' && reject(res.msg || res.data);
    19.                     }
    20.                 },
    21.                 error : err => {
    22.                     typeof reject === 'function' && reject(err.statusText);
    23.                 }
    24.             });
    25.         });
    26.     }

    3.页面引入

    1. const _mm = new MUtil();

    4.使用,传入参数

    1. // 首页数据统计
    2.    getHomeCount(){
    3.        return _mm.request({
    4.            url: '/manage/statistic/base_count.do'
    5.        });
    6.    }
  • 相关阅读:
    Two Sum II
    Subarray Sum
    Intersection of Two Arrays
    Reorder List
    Convert Sorted List to Binary Search Tree
    Remove Duplicates from Sorted List II
    Partition List
    Linked List Cycle II
    Sort List
    struts2结果跳转和参数获取
  • 原文地址:https://www.cnblogs.com/six-hc/p/12715258.html
Copyright © 2011-2022 走看看