Skip to main content

Using Piio Images in VueJS

Following this guide, you will be able to successfully optimize and deliver all your website images using Piio Images on Vue.

  1. Get your Domain Key
  2. Vue installation
  3. Get your images to work

1. Get your Domain Key#

The Piio Images library uses a Domain Key to identify your website and where the images are hosted. If you haven't created an account and added your first domain, follow the steps after signing up for a free account here.

2. Vue installation#

NPM Installation#

npm install piio-images-vue

Manual Installation#

If you aren't using npm installation, you can install Piio Images manually by following these steps:

  • Download the directory Piio-images containing piio.js, piio.vue, piioElement.js and piioElement.vue from our repository
  • Load piio.js in your code

Include the Piio Images components#

Add the following line to import the component in your main.js:

Vue.component('Piio', require('./components/piio/piio.vue').default);

Initialize the component by adding it to the App.vue:

<Piio domain-key="DOMAIN-KEY"/>

Getting as result:

<div id="app">
<Piio domain-key="DOMAIN-KEY"/>

Replace DOMAIN-KEY with the Domain Key for you domain. You can find your Domain Key on your dashboard at

3. Get your images to work#

PiioElement is a Vue component that will replace the usage of img tags or other HTML elements when you want to load an image.

PiioElement properties

  • tag(required) - defines which HTML tag will be used [img|div|a|..]
  • path(required) - URL of the image to be optimized and rendered on the HTML element
  • Any HTML valid attribute - PiioElements will pass all the attributes to the final HTML element

HTML <img> tag#

Add the PiioElement with the tag attribute set as img and the URL of the image in the path attribute.

<PiioElement tag="img" path="" alt="Piio Element" class="example-class"></PiioElement>

Background Images for <div> or other HTML tags#

Add the PiioElement with the tag attribute set as the element you want to have the background applied. You can add any other attributes and content to the element as it will be added.

Here is an example using an anchor tag:

<PiioElement path="" tag="a" href="">
<h1>Example content</h1>

HTML <picture> tag#

Each <source> inside your <picture> tag will be replaced with a PiioElement, the tag property will be set to source, and the URL of the image will be included in the path attribut

<PiioElement path="" tag="source" media="(min-width:969px)">
<PiioElement path="" tag="source" media="(max-width:969px)">
<PiioElement path="" tag="img">

Read more about Art Direction here.


If you don't want to use our components, you can take a look at the guide to integration Piio Images manually on any HTML based web application here.