A Vue renderer for the Strapi's Blocks rich text editor. Compatible with Nuxt.
npm install vue-strapi-blocks-renderer[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![License][license-src]][license-href]


Easily render the content of Strapi's new Blocks rich text editor in your Vue frontend.
Based on @strapi/blocks-react-renderer
- ✨ Release Notes
- 👀 Demo
- 🏀 Online stackblitz playground
- Zero runtime dependencies
- Renders line breaks (\n) as elements
- plainText prop available on code and heading blocks
- useStrapiBlocksContext() composable for nested custom components
- Custom block and modifier components
- Full TypeScript support
- Compatible with Nuxt
Install the Blocks renderer and its peer dependencies:
``sh`
npm install vue-strapi-blocks-renderer vue
After fetching your Strapi content, you can use the BlocksRenderer component to render the data from a blocks attribute. Pass the array of blocks coming from your Strapi API to the content prop:
`vue
`
You can provide your own Vue components to the renderer, both for blocks and modifiers. They will be merged with the default components, so you can override only the ones you need.
- Blocks are full-width elements, usually at the root of the content:
- paragraphheading
- (receives level, plainText)list
- (receives format)quote
- code
- (receives plainText)image
- (receives image)link
- (receives url, target, rel)bold
- Modifiers are inline elements for text formatting:
- italic
- underline
- strikethrough
- code
-
To provide your own components, pass an object to the blocks and modifiers props. Each value should be a Vue render function that receives the props. Make sure to always render the children so nested content is displayed.
`vue
`
If you need to access the blocks/modifiers context from within a custom component, use the useStrapiBlocksContext() composable:
`ts
import { h } from 'vue'
import { useStrapiBlocksContext, type BlockChildren } from 'vue-strapi-blocks-renderer'
const CustomParagraph = (props: { children?: BlockChildren }) => {
const { modifiers } = useStrapiBlocksContext()
const modifierCount = Object.keys(modifiers).length
return h('p', {}, [
props.children,
h('small', { class: 'text-gray-500' }, (${modifierCount} modifiers available)),``
])
}
[npm-version-src]: https://img.shields.io/npm/v/vue-strapi-blocks-renderer/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/vue-strapi-blocks-renderer
[npm-downloads-src]: https://img.shields.io/npm/dm/vue-strapi-blocks-renderer.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-downloads-href]: https://npmjs.com/package/vue-strapi-blocks-renderer
[license-src]: https://img.shields.io/npm/l/vue-strapi-blocks-renderer.svg?style=flat&colorA=18181B&colorB=28CF8D
[license-href]: https://npmjs.com/package/vue-strapi-blocks-renderer