本地瀏覽器測試沒有問題,但是在移動設備上出現了調用方法值一直會進行緩存的問題。
由於代碼使用了閉包,原以為是這個原因造成的,聲明了新的變量並不起作用,百度了半天才發現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) }) }