nuxt / ui

A UI Library for Modern Web Apps, powered by Vue & Tailwind CSS.
https://ui.nuxt.com
MIT License
3.4k stars 374 forks source link

How to load the content of a json file into a ContentSearch #1724

Open rainer85ah opened 3 weeks ago

rainer85ah commented 3 weeks ago

Description

Hi, gang,

I'm trying to load the content of a json file using Nuxt3 and UI Pro but everything I have tried didn't work so now I'm asking for help. The goal is to show a list of companies' names and symbols in the ContentSearch modal.

This use case will help a lot of people as I couldn't find anything relevant about this topic.

Thanks!

The json file is inside /content/companies.json Content of the json file: {"APPL": "Apple Inc.", "GOOGL": "Alphabet Inc."}

I'm using the latest version of every package.

nuxt.config.ts: ssr: true, content: { documentDriven: true, experimental: { search: { indexed: true }, }, },

app.vue: ` import type { ParsedContent } from '@nuxt/content/dist/runtime/types' const { data: files } = useLazyFetch('/api/search.json', { server: false }) provide('files', files)

`

/server/api/search.json.get.ts: import { serverQueryContent } from '#content/server' export default eventHandler(async (event) => { return serverQueryContent(event).where({ title: 'search_biz' }).findOne() })

benjamincanac commented 2 weeks ago

I'm not sure to understand what you're trying to achieve, have you checked the documentation of the ContentSearch component? https://ui.nuxt.com/pro/components/content-search#usage

It shows an example with @nuxt/content.