fetch缓存问题

本地浏览器测试没有问题,但是在移动设备上出现了调用方法值一直会进行缓存的问题。

由于代码使用了闭包,原以为是这个原因造成的,声明了新的变量并不起作用,百度了半天才发现fetch这个东西有一个缓存设置cache: "force-cache",按照说明修改为no-cache,问题搞定!!!

if (window.fetch && method == 'fetch') {
        let requestConfig = {
            credentials: 'include',
            method: type,
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'Authorization':"Bearer " + localStorage.getItem("access_token2"),//gougou 2021-5-12
            },
            mode: "cors",
            //cache: "force-cache"//会有缓存
            cache:"no-cache"
        }

        if (type == 'POST' || type == 'DELETE') {
            Object.defineProperty(requestConfig, 'body', {
                value: JSON.stringify(data)
            })
        }

 

posted @ 2021-06-02 11:59  无聊的蚂蚁  阅读(1486)  评论(0编辑  收藏  举报