# Nuxt

Use the rupa-player custom element in Nuxt, loaded in onMounted so server rendering keeps your text.

## Quick start

1. Install the player.

   ```sh
   npm i @rupamotion/player
   ```

2. Put `hero.rupaplay` (export as **Player file** in Rupamotion) in `public/`.

3. Mark `rupa-player` as a custom element in `nuxt.config` (`vue.compilerOptions.isCustomElement`):

   ```ts
   // nuxt.config.ts
   export default defineNuxtConfig({
   	vue: { compilerOptions: { isCustomElement: (tag) => tag === "rupa-player" } },
   });
   ```

4. Load the element in `onMounted` and use it in a component. The element loads in the browser only:

   ```vue
   <script setup>
   onMounted(() => import("@rupamotion/player/element"));
   </script>

   <template>
   	<rupa-player src="/hero.rupaplay"></rupa-player>
   </template>
   ```

That's it: the animation plays.

## Need control?

The element's `player` is the player once the file is mounted (`null` before). A template `ref` is the element:

```vue
<script setup>
const hero = ref(null);
onMounted(() => import("@rupamotion/player/element"));
</script>

<template>
	<rupa-player ref="hero" src="/hero.rupaplay"></rupa-player>
	<button @click="hero?.player?.pause()">Pause</button>
</template>
```

See [Control playback](/guides/control/) and [Events](/guides/events/).
