# Using Sirv Media Viewer with Vue.js

[Sirv Media Viewer](/help/sirv-media-viewer/) is a modern tool for displaying 360 degree spins, [3D models](/help/sirv-media-viewer/media-types/3d-model/), images and videos, either separately or in a gallery.

Using an AI coding agent?

Install the [`sirv-media-viewer`](https://www.skills.sh/sirv/image-optimization-skill/sirv-media-viewer) skill, and your agent can add the viewer to your site. Ask in plain words, such as “Add a gallery with zoom and a [360 spin](/help/spin/getting-started/how-spin-files-are-created/) to the product page.” [See all 8 skills](/help/rest-api/sirv-skills-for-ai-agents/)

Here’s a list of Sirv Media Viewer components you can use in a Vue.js app, either alone, in a [gallery](/help/sirv-media-viewer/) or in a [smart gallery](/help/sirv-media-viewer/core-features/smart-gallery/):

-   [Image Zoom](/help/integrations/vuejs/vue-js-image-zoom/)
-   [360 Spin and 3D models](/help/integrations/vuejs/vue-js-360-viewer-360-3d-spin/)
-   [Responsive Images](/help/sirv-media-viewer/core-features/responsive-images/)
-   [Video](/help/integrations/vuejs/vue-js-video-player/)

## Demo

[View full demo on StackBlitz](https://stackblitz.com/edit/daisyui-vue-vite-ogvk6w?file=src%2FApp.vue)

## Getting started

To get the most from Sirv (dynamic image resizing, image zoom tiling and much more):

1.  [Create a Sirv account](https://app.sirv.com/signup) (or [log in](https://app.sirv.com/login)).
2.  [Upload media](/help/file-upload/upload-images/) to your Sirv account.

### Install Sirv Media Viewer npm package

```bash
npm install @sirv/sirvjs-vue
#pnpm add @sirv/sirvjs-vue
#yarn add @sirv/sirvjs-vue
```

### Register Sirv Media Viewer as a plugin

```js
import { createApp } from 'vue';
import App from './App.vue';
import SirvjsVue from '@sirv/sirvjs-vue';
const app = createApp(App);

app.use(SirvjsVue);
app.mount('#app');
```

### Load Sirv JS

You can load the Sirv Media Viewer script in your HTML:

```html
<script src="https://scripts.sirv.com/sirvjs/v3/sirv.js"></script>
```

If you need finer control, use the `loadScript` module:

```js
import { loadScript } from '@sirv/sirvjs-vue';
loadScript().then((sirv) => {
    sirv.start();
})
```

## Using the component

There are two ways you can use the Sirv Media Viewer component in your Vue app.

### `slides` array

```html
<sirv-media-viewer
:slides="[
  {
    src: 'https://demo.sirv.com/demo/Switch/switch-front.jpg',
    type: 'zoom',
  },
  {
    src: 'https://demo.sirv.com/Examples/Coach/Coach.spin',
    type: 'spin',
  },
  {
    src: 'https://demo.sirv.com/demo/Switch/nintendo_switch.glb',
    type: 'model',
  },
  {
    src: 'https://demo.sirv.com/demo/Switch/switch.mp4',
    type: 'video',
  },
]"
></sirv-media-viewer>
```

The `slides` object accepts other props, which you can find [below](#props).

### `div` options

Alternatively, you can use the component by adding each element of the gallery as a `div`, for example:

```html
<sirv-media-viewer data-options="fullscreen.enable:false;">
<div
    data-type="zoom"
    data-src="https://demo.sirv.com/demo/Switch/switch-front.jpg"
></div>
<div
    data-type="spin"
    data-src="https://demo.sirv.com/Examples/Coach/Coach.spin"
    data-options="column.reverse:true;"
></div>
<div
    data-type="model"
    data-src="https://demo.sirv.com/demo/Switch/nintendo_switch.glb"
></div>
<div
    data-type="video"
    data-src="https://demo.sirv.com/demo/Switch/switch.mp4"
></div>
</sirv-media-viewer>
```

You can apply data types and data options in the div itself. [View all available options](/help/sirv-media-viewer/overview/#options).

### Props

**`slides`**

-   `:id` - viewer id
-   `:data-src` - used for `*.view` files, overrides `:slides`. [.view files documentation](/help/sirv-media-viewer/core-features/smart-gallery/)
-   `data-options`. [Full list of options](/help/sirv-media-viewer/overview/#options).
-   `:slides` - an Array with slide sources. Sources can be a String or an Object.

A String accepts an url, eg `https://demo.sirv.com/Examples/Coach/Coach.spin`  
An Object has additional props:

-   `id` - Slide id \[String\]
-   `src` - Source \[String\]
-   `dataOptions` - Local slide options \[Object\]
-   `type` - Type of slide \[String\]. The available props are: `spin`, `zoom`, `image`, `model`, `youtube`, `vimeo`, `video`, `html`
-   `dataThumbnailImage` - Custom thumbnail image \[String\]
-   `dataThumbnailHtml` - Custom thumbnail html \[String\]
-   `dataDisabled` - Disable slide \[Boolean\]
-   `dataSwipeDisabled` - Disable slide swipe \[Boolean\]
-   `dataHiddenSelector` - Hide selector \[Boolean\]
-   `dataPinned` - Pinned selector \[String\]. The available props are: `left`, `right`
-   `staticImage` - Static image \[Boolean\].

## Responsive image component

Achieving perfectly sized responsive images delivered in the [optimal format](/help/dynamic-imaging/format-quality/format/) is a piece of cake with Sirv Media Viewer. Here’s an example:

![Tomatoes and basil](https://demo.sirv.com/tomatoes-basil.jpg)

```html
<sirv-image
    data-src='https://demo.sirv.com/tomatoes-basil.jpg'
    data-options="threshold:100;"
></sirv-image>
```

[Full list of options](/help/sirv-media-viewer/core-features/responsive-images/#options).

## Using the Sirv API and events

You have full control of the viewer experience with API methods and events:

-   [Sirv JS API methods](/help/sirv-media-viewer/advanced-implementation/api/)
-   [Sirv JS events](/help/sirv-media-viewer/advanced-implementation/events/)

Here is a sample component:

```html
<template>
 <sirv-media-viewer :id="id" data-src="https://demo.sirv.com/Examples/b74317.view" ></sirv-media-viewer>
  <div class="flex justify-center my-5">
    <button class="btn mr-2" @click="prev">Previous</button>
    <button class="btn" @click="next">Next</button>
  </div>
</template>
  <script setup>
import { onMounted, ref } from 'vue';
import { loadScript } from '@sirv/sirvjs-vue';

const viewer = ref(null);
const id = ref('smv-test');
const prev = () => {
  if (viewer.value) {
    viewer.value.prev();
  }
};

const next = () => {
  if (viewer.value) {
    viewer.value.next();
  }
};

onMounted(() => {
  loadScript().then((sirv) => {
    sirv.start();
    sirv.on('viewer:ready', (e) => {
      if (e.id === 'smv-test') {
        viewer.value = e;
        console.log('viewer:ready', e);
      }
    });
  });
});
</script>
```

## Nuxt

### Install the npm package

```bash
npm install @sirv/sirvjs-vue
#pnpm add @sirv/sirvjs-vue
#yarn add @sirv/sirvjs-vue
```

### Register as a Nuxt plugin

```js
import SirvjsVue from '@sirv/sirvjs-vue';
export default defineNuxtPlugin(nuxtApp => {
    nuxtApp.vueApp.use(SirvjsVue, {})
})
```

### Load Sirv JS

You can load the script (`https://scripts.sirv.com/sirvjs/v3/sirv.js` globally via the [useHead composable](https://nuxt.com/docs/getting-started/seo-meta#usehead), or in the nuxt config head section.

If you need more control, you can load it via `loadScript`:

```js
import { loadScript } from '@sirv/sirvjs-vue';
loadScript().then((sirv) => {
    sirv.start();
})
```

If your prefer to use Nuxt Image to handle your static images, you can use our official [Sirv provider for Nuxt Image](/help/integrations/vuejs/using-sirv-cdn-with-nuxt/).

## Gridsome

The approach explained above should work fine with Gridsome. If you only need the Image CDN functionality of Sirv, you can use this third-party plugin: [gridsome-plugin-image-cdn](https://gridsome.org/plugins/gridsome-plugin-image-cdn).

We hope that helped show how easily you can embed responsive images, 360 spins, videos and image zooms in your Vue.js website or app.
