• 微信公众号ios10.1 版本白屏问题


    真机调试IOS 10.1.x的版本不支持fetch 所以一直loading显示白屏。
    其他设备都没问题。 所以用主要属性window.fetch用来判断是否支持fetch 属性
    import {
        baseUrl
    } from './env'
    
    export default async(url = '', data = {}, type = 'GET', method = 'fetch') => {
        type = type.toUpperCase();
        url = baseUrl + url;
    
        if (type == 'GET') {
            let dataStr = ''; //数据拼接字符串
            Object.keys(data).forEach(key => {
                dataStr += key + '=' + data[key] + '&';
            })
    
            if (dataStr !== '') {
                dataStr = dataStr.substr(0, dataStr.lastIndexOf('&'));
                url = url + '?' + dataStr;
            }
        }
    
        if (window.fetch && method == 'fetch') {
            let requestConfig = {
                credentials: 'include',
                method: type,
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
            'Authorization': localStorage.getItem('token'),
                },
                mode: "cors",
                // cache: "force-cache"
            }
    
            if (type == 'POST') {
                Object.defineProperty(requestConfig, 'body', {
                    value: JSON.stringify(data)
                })
            }
    
            try {
                const response = await fetch(url, requestConfig);
                const responseJson = await response.json();
                return responseJson
            } catch (error) {
                throw new Error(error)
            }
        } else {
            return new Promise((resolve, reject) => {
                let requestObj;
                if (window.XMLHttpRequest) {
                    requestObj = new XMLHttpRequest();
                } else {
                    requestObj = new ActiveXObject;
                }
    
                let sendData = '';
                if (type == 'POST') {
                    sendData = JSON.stringify(data);
                }
    
                requestObj.open(type, url, true);
                requestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                requestObj.setRequestHeader("Accept","application/json");
          requestObj.setRequestHeader("Content-Type","application/json");
          requestObj.setRequestHeader("Authorization",localStorage.getItem('token'));
                requestObj.send(sendData);
    
                requestObj.onreadystatechange = () => {
                    if (requestObj.readyState == 4) {
                        if (requestObj.status == 200) {
                            let obj = requestObj.response
                            if (typeof obj !== 'object') {
                                obj = JSON.parse(obj);
                            }
                            resolve(obj)
                        } else {
                            reject(requestObj)
                        }
                    }
                }
            })
        }
    }
  • 相关阅读:
    Exadata存储节点的CPU限制成功了没?
    如何减少Exadata计算节点CPU的Core数量
    如何选择适合你的HTAP数据库?
    小知识:Oracle中的层次查询
    小知识:使用MOS下载Oracle介质快速参考
    小知识:Flex ASM特性对集群资源显示的影响
    javaWeb request请求乱码、response响应中文乱码一站式解决方案
    java 文件File与byte[]数组相互转换的两种方式
    pr 如何调高导出视频的清晰度?
    pr 剪辑视频之剃刀用法
  • 原文地址:https://www.cnblogs.com/wupeng88/p/11818670.html
Copyright © 2020-2023  润新知