Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
How to add vue3-openlayers plugin to nuxt

I have the following main.ts file in Vue3:

import { createApp } from "vue"
import App from "./App.vue";

//How to do this in nuxt3?
import OpenLayersMap from "vue3-openlayers";
import "vue3-openlayers/dist/vue3-openlayers.css";

const app = createApp(App);

//How to do this in nuxt3?
app.use(OpenLayersMap);

app.mount("#app");

How can I add the vue3-openlayers plugin to nuxt3?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To auto-install a Vue plugin in Nuxt 3, create a .js/.ts file under <projectDir>/plugins/ (create the directory if needed) with the following boilerplate:

// plugins/my-plugin.js
import { defineNuxtPlugin } from '#app'

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.vueApp.use(/* MyPlugin */)
})

Since vue3-openlayers depends on window, the plugin can only be installed client side, so use the .client.js extension.

To load vue3-openlayers client side, the plugin file would look like this:

// plugins/vue3-openlayers.client.js
import { defineNuxtPlugin } from '#app'
import OpenLayers from 'vue3-openlayers'

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.vueApp.use(OpenLayers)
})

Create <projectDir>/components/MyMap.vue with the following example content from the vue3-openlayers docs:

// components/MyMap.vue
<script setup>
import { ref } from 'vue'
const center = ref([40, 40])
const projection = ref('EPSG:4326')
const zoom = ref(8)
const rotation = ref(0)
</script>

<template>
  <ol-map :loadTilesWhileAnimating="true" :loadTilesWhileInteracting="true" style="height:400px">
    <ol-view :center="center" :rotation="rotation" :zoom="zoom"
    :projection="projection" />
    <ol-tile-layer>
        <ol-source-osm />
    </ol-tile-layer>
  </ol-map>
</template>

<style scoped>
@import 'vue3-openlayers/dist/vue3-openlayers.css';
</style>

We only want to render MyMap on the client because the plugin is only client-side, so use the <ClientOnly> component as a wrapper:

// app.vue
<template>
  <ClientOnly>
    <MyMap />
    <template #fallback> Loading map... </template>
  </ClientOnly>
</template>

demo

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda