Vue Friendly Iframe

0.20.0 · active · verified Sun Apr 19

Vue Friendly Iframe is a Vue.js component designed to simplify the creation and management of dynamic, asynchronous iframes, based on Aaron Peters' iframe loading techniques. The current stable version is 0.20.0, with releases occurring somewhat irregularly but indicating active maintenance, often driven by feature additions or bug fixes. Its primary differentiator is providing a controlled, event-driven mechanism for loading external content within an iframe, making it easier to interact with the iframe's lifecycle and attributes. It specifically supports Vue 2.x projects and integrates as a Vue plugin, offering props for `src`, `sandbox`, `allow`, `allowfullscreen`, and custom events for load states, aiming to provide a safer and more performant iframe experience compared to native iframe usage. It abstracts away some of the complexities of handling iframe content and security attributes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `vue-friendly-iframe` as a Vue plugin, set its source, and handle `load` and `message` events, including essential `sandbox` and `allow` attributes for security and functionality.

import Vue from 'vue';
import VueFriendlyIframe from 'vue-friendly-iframe';

Vue.use(VueFriendlyIframe);

new Vue({
  el: '#app',
  data: {
    iframeSrc: 'https://example.com/some-content',
    iframeLoaded: false,
    iframeMessage: ''
  },
  methods: {
    onIframeLoad() {
      this.iframeLoaded = true;
      console.log('Iframe content loaded!');
    },
    onIframeMessage(event) {
      this.iframeMessage = event.data;
      console.log('Message from iframe:', event.data);
    }
  },
  template: `
    <div>
      <h1>My App with Friendly Iframe</h1>
      <p v-if="!iframeLoaded">Loading iframe...</p>
      <p v-else>Iframe loaded!</p>
      <p v-if="iframeMessage">Message received: {{ iframeMessage }}</p>
      <vue-friendly-iframe
        :src="iframeSrc"
        @load="onIframeLoad"
        @message="onIframeMessage"
        sandbox="allow-scripts allow-same-origin"
        allow="fullscreen"
        style="width: 100%; height: 500px; border: 1px solid #ccc;"
      ></vue-friendly-iframe>
    </div>
  `
});

view raw JSON →