Learn how to use the newsletter module in your Nuxt 3 application.
This module exposes composables and components that are auto-imported by Nuxt 3.
In order to use nuxt-newsletter
module in your Nuxt application, make sure to register the module with its options in nuxt.config.ts
like following:
export default defineNuxtConfig({ modules: [ 'nuxt-newsletter' ], newsletter: { revue: { apiKey: '<REVUE_API_KEY>', component: true } }})
You can read about module configuration options here
NewsletterForm.vue
in your appRight now, you can use the built in newsletter-form
component in your application like following:
<template> <div> <newsletter-form /> </div></template>
You can read more about components in the Components section.
useNewsletterSubscribe
composableIf you prefer to create your own newsletter component you can use the built in useNewsletterSubscribe
composable to handle adding new email address to subscribers like following:
<script setup>const result = await useNewsletterSubscribe(email.value)console.log(result) // Email ${email} added to subscribers</script>