1.1.1 • Published 3 years ago

@praffn/vue-dato-image v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Vue Dato Image

Component for workig with images in DatoCMS.

Installation

npm install @praffn/vue-dato-image

or

yarn add @praffn/vue-dato-image

Usage

<template>
  <div>
    <DatoImage v-if="imageData" :data="imageData" />
  </div>
</template>

<script>
import gql from "graphql-tag";

export default {
  data() {
    return {
      imageData: null,
    };
  },
  async mounted() {
    const { data } = await this.$dato({
      query: gql`
        {
          page {
            image {
              responsiveImage {
                alt
                title
                base64
                bgColor
                width
                height
                sizes
                srcSet
                webpSrcSet
                src
              }
            }
          }
        }
      `,
    });
    this.imageData = data.page.image;
  },
};
</script>

Props

proptyperequireddescriptiondefault
dataResponsiveImage objectThe responsive you get from a DatoCMS reponsiveImage query
fadeInDurationnumberDuration (in ms) of the fade in transition when image has loadednull
intersectionTresholdnumberA value between 0.0 and 1.0 indicating at what percentage of the placeholder visibility that the image should start loading. 0.0 meas at soon as just one pixel is in the viewport and 1.0 means that the entire placeholder has to be in the viewport to start loading the actual image.0.0
intersectionMarginstringThe margins around the placeholder when considering intersection. Value should be like the CSS counterpart (top, right, bottom, left) and can be pixels as well as percentages. Used to compute the bounding box before computing intersection."0px 0px 0px 0px"
lazyloadbooleanWhether lazy loading is enabled or not. If not enabled the image will be eagerly loaded and intersection will not be computed.true

The ResponsiveImage object

This should be the object returned from your GraphQL query. There are some required properties:

propertytyperequireddescription
aspectRationumberThe aspect ratio of the image
widthnumberThe width of the image
heightnumberThe height of the image
sizesstringThe HTML5 sizes attribute for the image
srcSetstringThe HTML5 srcset attribute for the image
webpSrcSetstringThe HTML5 srcset attribute for the image in WebP format (for browsers that support that)
altstringAlternative text alt for the image. Not required but recommended for acceisiblity reasons if the image is important for the content
titlestringTitle attribute title for the image
bgColorstringThe background color for the image placeholder
base64stringA base64-encoded thumbnail used for the placeholder
1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago