useEffect(async () => {
caches.open('my-cache')
}, [token, user_id])
当我尝试注销我的应用程序时
const logoutFunc = () => {
localStorage.clear()
caches.keys().then((list) =>
list.map((key) => {
caches.delete(key)
router.push('/')
})
)
当它运行时,它会抛出类似的错误,
缓存已清除。但它会抛出错误
您可以通过在代码中添加 catch 块来捕获错误。
caches.keys().then((list) =>
list.map((key) => {
caches.delete(key)
router.push('/')
}).catch(e => ...)
解决方案可以去掉useEffect中的异步函数,阅读下面的文章。
useEffect(async () => {
caches.open('my-cache')
}, [令牌, user_id])