2022-07-07 16:26:04 +00:00
|
|
|
<script setup lang="ts">
|
2023-07-05 09:35:45 +00:00
|
|
|
import { useCustomKeyedComposable } from '~/other-composables-folder/custom-keyed-composable'
|
|
|
|
|
2022-08-05 11:02:20 +00:00
|
|
|
const useLocalState = () => useState(() => {
|
2023-08-07 22:03:40 +00:00
|
|
|
if (import.meta.client) { console.error('running usestate') }
|
2022-08-05 11:02:20 +00:00
|
|
|
return { foo: Math.random() }
|
|
|
|
})
|
2022-07-07 16:26:04 +00:00
|
|
|
const useStateTest1 = useLocalState()
|
|
|
|
const useStateTest2 = useLocalState()
|
|
|
|
|
2022-08-05 11:02:20 +00:00
|
|
|
const useLocalAsyncData = () => useAsyncData(() => {
|
2023-08-07 22:03:40 +00:00
|
|
|
if (import.meta.client) { console.error('running asyncdata') }
|
2022-08-05 11:02:20 +00:00
|
|
|
return Promise.resolve({ foo: Math.random() })
|
|
|
|
}, { transform: data => data.foo })
|
2022-07-07 16:26:04 +00:00
|
|
|
const { data: useAsyncDataTest1 } = await useLocalAsyncData()
|
|
|
|
const { data: useAsyncDataTest2 } = await useLocalAsyncData()
|
|
|
|
|
2022-08-05 11:02:20 +00:00
|
|
|
const useLocalLazyAsyncData = () => useLazyAsyncData(() => {
|
2023-08-07 22:03:40 +00:00
|
|
|
if (import.meta.client) { console.error('running asyncdata') }
|
2022-08-05 11:02:20 +00:00
|
|
|
return Promise.resolve({ foo: Math.random() })
|
|
|
|
}, { transform: data => data.foo })
|
2022-07-07 16:26:04 +00:00
|
|
|
const { data: useLazyAsyncDataTest1 } = await useLocalLazyAsyncData()
|
|
|
|
const { data: useLazyAsyncDataTest2 } = await useLocalLazyAsyncData()
|
|
|
|
|
2022-08-05 11:02:20 +00:00
|
|
|
const useLocalFetch = () => useFetch('/api/counter', {
|
|
|
|
transform: (data) => {
|
2023-08-07 22:03:40 +00:00
|
|
|
if (import.meta.client) { console.error('running client-side transform') }
|
2022-08-05 11:02:20 +00:00
|
|
|
return data.count
|
|
|
|
}
|
|
|
|
})
|
2022-07-07 16:26:04 +00:00
|
|
|
const { data: useFetchTest1 } = await useLocalFetch()
|
|
|
|
const { data: useFetchTest2 } = await useLocalFetch()
|
|
|
|
|
|
|
|
const useLocalLazyFetch = () => useLazyFetch(() => '/api/counter')
|
|
|
|
const { data: useLazyFetchTest1 } = await useLocalLazyFetch()
|
|
|
|
const { data: useLazyFetchTest2 } = await useLocalLazyFetch()
|
2023-03-07 21:06:15 +00:00
|
|
|
|
2023-06-05 19:15:12 +00:00
|
|
|
const useLocalCustomKeyedComposable = () => useCustomKeyedComposable()
|
|
|
|
const useMyAsyncDataTest1 = useLocalCustomKeyedComposable()
|
|
|
|
const useMyAsyncDataTest2 = useLocalCustomKeyedComposable()
|
2022-07-07 16:26:04 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-08-05 11:02:20 +00:00
|
|
|
<div>
|
2022-07-07 16:26:04 +00:00
|
|
|
{{ useStateTest1 === useStateTest2 }}
|
|
|
|
{{ useAsyncDataTest1 === useAsyncDataTest2 }}
|
|
|
|
{{ useLazyAsyncDataTest1 === useLazyAsyncDataTest2 }}
|
|
|
|
{{ useFetchTest1 === useFetchTest2 }}
|
|
|
|
{{ useLazyFetchTest1 === useLazyFetchTest2 }}
|
2023-03-07 21:06:15 +00:00
|
|
|
{{ !!useMyAsyncDataTest1 && useMyAsyncDataTest1 === useMyAsyncDataTest2 }}
|
2022-08-05 11:02:20 +00:00
|
|
|
</div>
|
2022-07-07 16:26:04 +00:00
|
|
|
</template>
|
2022-09-08 08:55:30 +00:00
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
body {
|
|
|
|
background-color: #000;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
</style>
|