mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-26 14:16:10 +00:00
fc2be9ed42
Co-authored-by: Pooya Parsa <pooya@pi0.io>
37 lines
905 B
Vue
37 lines
905 B
Vue
<template>
|
|
<div>
|
|
Single
|
|
<div>
|
|
data: {{ data }}
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
const called = ref(0)
|
|
const { data, execute } = await useAsyncData(() => Promise.resolve(++called.value), { immediate: false })
|
|
|
|
if (called.value !== 0) {
|
|
throw new Error('Handled should have not been called')
|
|
}
|
|
|
|
if (process.server && data.value !== null) {
|
|
throw new Error('Initial data should be null: ' + data.value)
|
|
}
|
|
|
|
await execute()
|
|
await execute()
|
|
|
|
if (process.server && called.value as number !== 2) {
|
|
throw new Error('Should have been called once after execute (server) but called ' + called.value + ' times')
|
|
}
|
|
|
|
if (process.client && called.value as number !== 2) {
|
|
throw new Error('Should have been called once after execute (client) but called ' + called.value + ' times')
|
|
}
|
|
|
|
if (data.value !== 2) {
|
|
throw new Error('Data should be 1 after execute')
|
|
}
|
|
</script>
|