【发布时间】:2019-11-02 10:17:33
【问题描述】:
我正在使用NUXT-PWA 来缓存我的数据,但我有一个依赖于要构建的POST 请求的页面,我需要缓存JSON 的响应,但我收到以下错误:
Uncaught (in promise) attempt-to-cache-non-get-request: Unable to cache '/api/hotel/order/get-voucher' because it is a 'POST' request and only 'GET' requests can be cached.
我在workbox-range-request.js 中使用的代码是这样的:
workbox.routing.registerRoute(
new RegExp('/api/(.*)'),
new workbox.strategies.CacheFirst({
cacheName: 'apiCache',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 100,
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 Days
}),
],
}),
'POST'
);
还有我的nuxt.config.js:
workbox: {
dev:true,
cachingExtensions: '@/plugins/workbox-range-request.js',
runtimeCaching: [
{
urlPattern: 'https://www.google-analytics.com/.*',
handler: 'StaleWhileRevalidate',
method: 'GET',
strategyOptions: { cacheableResponse: { statuses: [0, 200] } }
}
]
},
在文档中说它支持POST,但在控制台中我得到了错误,在我的cacheStore 中我没有数据。
【问题讨论】:
标签: progressive-web-apps nuxt.js workbox