Developers

    Use the UPCS Embed in Vue

    An illustrative Vue 3 pattern for the UPCS embeddable map: load the script, mount on onMounted, emit the selection and destroy on unmount.

    Updated 14 October 2026 · 2 min read

    UPCS has no official Vue plugin. The single-file component below is an illustrative implementation pattern using the documented embed script. It mounts the map when the component appears and destroys it when the component goes away.

    The component

    <script setup>
    import { onMounted, onBeforeUnmount, ref } from 'vue';
    
    const emit = defineEmits(['select']);
    const props = defineProps({ height: { type: String, default: '500px' } });
    const el = ref(null);
    let handle = null;
    
    function loadScript() {
      if (window.UPCS) return Promise.resolve();
      return new Promise((resolve, reject) => {
        const s = document.createElement('script');
        s.src = 'https://api.upcs.io/api/embed/upcs-embed.js';
        s.onload = resolve;
        s.onerror = reject;
        document.head.appendChild(s);
      });
    }
    
    onMounted(async () => {
      await loadScript();
      const res = await fetch('/upcs-session');
      const { session_token } = await res.json();
    
      el.value.id = el.value.id || 'upcs-map-' + Math.random().toString(36).slice(2);
      handle = window.UPCS.mount('#' + el.value.id, {
        sessionToken: session_token,
        height: props.height,
        onSelect: (result) => emit('select', result),
        onError: (err) => console.error('UPCS', err)
      });
    });
    
    onBeforeUnmount(() => {
      if (handle) handle.destroy();
    });
    </script>
    
    <template>
      <div ref="el"></div>
    </template>
    

    Using it

    <UpcsMap @select="order.upcsCode = $event.upcs_code" />
    

    Notes

    Remember to register your dev and production origins as described in allowed origins explained.

    Frequently asked questions

    Is there an official Vue plugin?

    No. UPCS provides no official SDKs. This is an illustrative pattern built on the documented script and UPCS.mount.

    Where do I get the session token?

    From an endpoint on your own server that calls the UPCS embed session API with your key.