mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
feat: add useCache and setCache for nuxtislands
This commit is contained in:
parent
bb533f8d25
commit
b48053a078
@ -44,6 +44,22 @@ export default defineComponent({
|
||||
source: {
|
||||
type: String,
|
||||
default: () => undefined
|
||||
},
|
||||
/**
|
||||
* use the NuxtIslandResponse which has been cached if available
|
||||
* @default true
|
||||
*/
|
||||
useCache: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
/**
|
||||
* allows to set the NuxtIslandResponse into the cache for future updates
|
||||
* @default true
|
||||
*/
|
||||
setCache: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
async setup (props, { slots }) {
|
||||
@ -130,7 +146,9 @@ export default defineComponent({
|
||||
appendResponseHeader(event, 'x-nitro-prerender', hints)
|
||||
}
|
||||
}
|
||||
setPayload(key, result)
|
||||
if (import.meta.client && props.setCache) {
|
||||
setPayload(key, result)
|
||||
}
|
||||
return result
|
||||
}
|
||||
const key = ref(0)
|
||||
@ -167,7 +185,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
if (import.meta.client) {
|
||||
watch(props, debounce(() => fetchComponent(), 100))
|
||||
watch(props, debounce(() => fetchComponent(!props.useCache), 100))
|
||||
}
|
||||
|
||||
if (import.meta.client && !nuxtApp.isHydrating && props.lazy) {
|
||||
|
@ -6,12 +6,14 @@ export const createServerComponent = (name: string) => {
|
||||
return defineComponent({
|
||||
name,
|
||||
inheritAttrs: false,
|
||||
props: { lazy: Boolean },
|
||||
props: { lazy: Boolean, useCache: { type: Boolean, default: true }, setCache: { type: Boolean, default: true } },
|
||||
setup (props, { attrs, slots }) {
|
||||
return () => {
|
||||
return h(NuxtIsland, {
|
||||
name,
|
||||
lazy: props.lazy,
|
||||
useCache: props.useCache,
|
||||
setCache: props.setCache,
|
||||
props: attrs
|
||||
}, slots)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user