Nuxt
@paperpic/nuxt is the module for Nuxt 4. It registers the PaperPic component of @paperpic/vue and adds its stylesheet to your app, so your templates can use the viewer without importing anything.
Installation
npm install @paperpic/nuxtpnpm add @paperpic/nuxtyarn add @paperpic/nuxtbun add @paperpic/nuxtThen add the module to nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@paperpic/nuxt'],
})@paperpic/vue comes with the module, so you do not need to install it yourself.
Usage
<script setup lang="ts">
import type { ExportedImage } from '@paperpic/nuxt'
function upload({ blob }: ExportedImage) {
// Send the edited image to your server
}
</script>
<template>
<div style="height: 480px">
<PaperPic src="/receipt.jpg" alt="A receipt" @apply="upload" />
</div>
</template>The component fills its parent element, so give the parent a height. It is the same component that @paperpic/vue exports, so the Vue page describes its props, events and methods.
The Vue examples in these docs work in Nuxt too. Leave out the lines that import the component and style.css from @paperpic/vue, and import the types from @paperpic/nuxt instead. Tests change a little too, as the Testing page shows.
Lazy loading
Nuxt also registers the component as <LazyPaperPic>, which downloads the code of the viewer only when it first renders, for example when the user opens a dialog. A page that does not show the viewer right away then loads less code. The stylesheet is part of the app, so it is already there when the viewer appears.
Types
@paperpic/nuxt exports every type of @paperpic/vue, so import your types from it, such as import type { PaperPicInstance } from '@paperpic/nuxt'. The Types page shows what each one holds.
Server-side rendering
The component renders an empty element on the server and creates the viewer in the browser when it mounts, so you do not need to wrap it in <ClientOnly>.
Options
The module has no options of its own yet. You set up each viewer with the props of the component, as in Vue.