feat: dynamic import recipe.json
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import recipeData from '~/data/recipe.json'
|
||||
import type { RecipeItem, Recipes } from '~/types'
|
||||
import type { DbRecipeItem } from 'utils/db'
|
||||
|
||||
/**
|
||||
* 随机几道菜
|
||||
@@ -7,9 +6,13 @@ import type { RecipeItem, Recipes } from '~/types'
|
||||
* @returns
|
||||
*/
|
||||
export function useRandomRecipe(total: Ref<number>) {
|
||||
const randomRecipes = ref<RecipeItem[]>([])
|
||||
function random() {
|
||||
randomRecipes.value = generateRandomRecipe(recipeData as Recipes, total.value)
|
||||
const randomRecipes = ref<(DbRecipeItem | undefined)[]>([])
|
||||
async function random() {
|
||||
const length = await db.recipes.count()
|
||||
const randomArr = generateRandomArray(length, total.value)
|
||||
const result = await db.recipes.bulkGet(randomArr)
|
||||
if (result)
|
||||
randomRecipes.value = result.filter(item => !!item)
|
||||
}
|
||||
|
||||
watch(total, () => {
|
||||
|
||||
Reference in New Issue
Block a user