diff --git a/components/RandomRecipe.vue b/components/RandomRecipe.vue
index 78257aa..2912240 100644
--- a/components/RandomRecipe.vue
+++ b/components/RandomRecipe.vue
@@ -16,11 +16,12 @@ const { random, randomRecipes } = useRandomRecipe(count)
+
+
-
diff --git a/composables/recipe.ts b/composables/recipe.ts
index 2fd0764..b9e1d2e 100644
--- a/composables/recipe.ts
+++ b/composables/recipe.ts
@@ -1,3 +1,5 @@
+import { useStorage } from '@vueuse/core'
+import { namespace } from '~/constants'
import type { DbRecipeItem } from '~/utils/db'
/**
@@ -5,7 +7,7 @@ import type { DbRecipeItem } from '~/utils/db'
* @param total
*/
export function useRandomRecipe(total: Ref) {
- const randomRecipes = ref<(DbRecipeItem | undefined)[]>([])
+ const randomRecipes = useStorage<(DbRecipeItem | undefined)[]>(`${namespace}:random:recipes`, [])
async function random() {
const length = await db.recipes.count()
const randomArr = generateRandomArray(length, total.value)
@@ -19,7 +21,9 @@ export function useRandomRecipe(total: Ref) {
})
onMounted(() => {
- random()
+ // 如果没有随机菜谱,就生成一次
+ if (randomRecipes.value.length <= 0)
+ random()
})
return {