Components

CldMediaLibrary

The CldMediaLibrary creates a media gallery element that uses an instance of the Cloudinary Media Library Widget to give you an easy way to add media librarry component to your Nuxt app.

Basic Usage

<script setup lang="ts">
const buttonId = "open-btn";
const apiKey = useRuntimeConfig().public.cloudinary.apiKey;
</script>

<template>
  <div>
    <button :id="buttonId">Select Image or Video</button>
    <CldMediaLibrary :api-key="apiKey" :button-id="buttonId" />
  </div>
</template>

Props

CldMediaLibrary accepts several customization props listed below:

Prop NameTypeExample
cloudNamestring"demo"
apiKeystring"12345"
buttonIdstring"my-btn"
usernamestring"user"
useSamlbooleanfalse
paramsobject{}

For all other available props checkout Cloudinary Media Gallery Docs and make sure to pass them to the component as params like following:

<script setup lang="ts">
const buttonId = "open-btn";
const apiKey = useRuntimeConfig().public.cloudinary.apiKey;

const params = {
  sortProps: {
    button_caption: "Open Media Library",
    insert_caption: "Insert",
    remove_header: false,
    max_files: 6,
  },
};
</script>

<template>
  <div>
    <button :id="buttonId">Select Image or Video</button>
    <ClsMediaLibrary :api-key="apiKey" :button-id="buttonId" :params="params" />
  </div>
</template>

Events

ClsMediaLibrary emits following events:

Event NameTypeExample
onInsertfunction(data) => { }

You can use this event like following:

<script setup lang="ts">
const buttonId = "open-btn";
const apiKey = useRuntimeConfig().public.cloudinary.apiKey;

function handleInsert(data: unknown) {
  console.log(data)
}
</script>

<template>
  <div>
    <button :id="buttonId">Select Image or Video</button>
    <ClsMediaLibrary
      :api-key="apiKey"
      :button-id="buttonId"
      :params="params"
      @on-insert="handleInsert"
    />
  </div>
</template>