2023-12-14 17:11:08 +00:00
|
|
|
export default defineNuxtPlugin({
|
|
|
|
name: 'async-plugin',
|
|
|
|
async setup (/* nuxtApp */) {
|
|
|
|
const config1 = useRuntimeConfig()
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 100))
|
|
|
|
const { data } = useFetch('/api/hey', { key: 'hey' })
|
|
|
|
const config2 = useRuntimeConfig()
|
|
|
|
return {
|
|
|
|
provide: {
|
|
|
|
asyncPlugin: () => config1 && config1 === config2
|
|
|
|
? 'Async plugin works! ' + config1.public.testConfig + (data.value?.baz ? 'useFetch works!' : 'useFetch does not work')
|
|
|
|
: 'Async plugin failed!'
|
|
|
|
}
|
2022-04-01 09:55:23 +00:00
|
|
|
}
|
2023-12-14 17:11:08 +00:00
|
|
|
},
|
|
|
|
parallel: true
|
2022-04-01 09:55:23 +00:00
|
|
|
})
|