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.    }
  • 相关阅读:
    禁止进入activity自动弹出键盘
    sqlite的limit使用
    关于anroid设置webview背景方法探讨(转)
    遍历ListView,查出每一项的内容
    虚拟机网络不通故障解决
    zabbix第一篇:zabbix安装及使用
    ansible使用1
    PS1修改xshell命令行样式
    手动配置网卡配置文件ifcfg-eth0
    Linux虚拟机centos系统安装
  • 原文地址:https://www.cnblogs.com/six-hc/p/12715258.html
Copyright © 2011-2022 走看看