Movatterモバイル変換


[0]ホーム

URL:


Nuxt UI v3 is officially released.
Discover Nuxt UI Pro

BlogPostsPRO

Display a list of blog posts in a responsive grid layout.

Usage

The BlogPosts component provides a flexible layout to display a list ofBlogPost components using either the default slot or theposts prop.

<template>  <UBlogPosts>    <UBlogPost      v-for="(post,index) inposts"      :key="index"      v-bind="post"    />  </UBlogPosts></template>

Posts

Use theposts prop as an array of objects with the properties of theBlogPost component.

Orientation

Use theorientation prop to change the orientation of the BlogPosts. Defaults tohorizontal.

Examples

While these examples useNuxt Content v3, the components can be integrated with any content management system.

Within a page

Use the BlogPosts component in a page to create a blog page:

pages/blog/index.vue
<script setup lang="ts">const { data: posts} = await useAsyncData('posts', () => queryCollection('posts').all())</script><template>  <UPage>    <UPageHero title="Blog" />    <UPageBody>      <UContainer>        <UBlogPosts>          <UBlogPost            v-for="(post,index) inposts"            :key="index"            v-bind="post"            :to="post.path"          />        </UBlogPosts>      </UContainer>    </UPageBody>  </UPage></template>
In this example, theposts are fetched usingqueryCollection from the@nuxt/content module.
Theto prop is overridden here since@nuxt/content uses thepath property.

API

Props

Prop Default Type
as

'div'

any

The element or component this component should render as.

posts

BlogPostProps[]

orientation

'horizontal'

"vertical" | "horizontal"

The orientation of the blog posts.

Slots

Slot Type
default

{}

Theme

app.config.ts
export default defineAppConfig({  uiPro: {    blogPosts: {      base: 'flex flex-col gap-8 lg:gap-y-16',      variants: {        orientation: {          horizontal: 'sm:grid sm:grid-cols-2 lg:grid-cols-3',          vertical: ''        }      }    }  }})
vite.config.ts
import { defineConfig } from 'vite'import vuefrom '@vitejs/plugin-vue'import uifrom '@nuxt/ui/vite'export default defineConfig({  plugins: [    vue(),    ui({      uiPro: {        blogPosts: {          base: 'flex flex-col gap-8 lg:gap-y-16',          variants: {            orientation: {              horizontal: 'sm:grid sm:grid-cols-2 lg:grid-cols-3',              vertical: ''            }          }        }      }    })  ]})
vite.config.ts
import { defineConfig } from 'vite'import vuefrom '@vitejs/plugin-vue'import uiProfrom '@nuxt/ui-pro/vite'export default defineConfig({  plugins: [    vue(),    uiPro({      uiPro: {        blogPosts: {          base: 'flex flex-col gap-8 lg:gap-y-16',          variants: {            orientation: {              horizontal: 'sm:grid sm:grid-cols-2 lg:grid-cols-3',              vertical: ''            }          }        }      }    })  ]})

[8]ページ先頭

©2009-2025 Movatter.jp