Vuex State Synchronization Between iFrame/Window Component

vuex-iframe-sync is the synchronization of the Vuex state between iframes/windows.

Features:

  • Support iframes/sync window
  • Sync configuration when the iframe is loaded
  • Configure sync behavior for your own needs

Note: window.postMessage has a limitation on the message, and it works like JSON.parse() and JSON.stringfy(). If you have a problem with that, configure a transform function in the broadcast and transfer API.

How to make use of it:

Installation:

NPM
npm install vuex-iframe-sync --save

YARN
yarn add vuex-iframe-sync

Usage

// in parent's component with iframe
<iframe id="frameId1"/>
<iframe id="frameId2"/>

// in parent's store.js
import {broadcast} from 'vuex-iframe-sync'

export default new Vuex.store({
  // ...
  plugins: [
    broadcast('frameId1,frameId2')
  ]
})

// in iframe's store.js
import {transfer} from 'vuex-iframe-sync'

export default new Vuex.store({
  // same state and mutations with parent
  plugins: [
    transfer()
  ]
})

API

broadcast(ids: String, [options])

Send state changes payload to iframes through postMessage API while parent state changes.

ids <String|Array>: frameIds split by ‘,’ or [{id: iframeId, origin: iframeOrigin}…]

options : The following options can be provided to configure the parent behavior for your specific needs:

  • convert <Function(payload)>: convert payload before passing to iframes.

transfer([options])

Receive state changes from a parent. Send state changes to parent while self-state changes.

options : The following options can be provided to configure the iframe behavior for your specific needs:

  • convert <Function(payload)>: convert payload before passing to parent.
  • created <Function(id, store, send)>: call after the iframe is created. id: iframeId、store: this.store、send<Function(type, payload)>:parent.$store.commit: call after iframe destroyed. id: iframeId、store: this.store、send<Function(type, payload)>:parent.$store.commit

vuex state synchronization between iframes, vuex-iframe-sync plugin/github


See Demo And Download

Official Website(L-Chris): Click Here

This superior jQuery/javascript plugin is developed by L-Chris. For extra advanced usage, please go to the official website.

Related Posts

Data-Table-Generator-Tabulator

Interactive Data Table Generator with JS/jQuery and JSON | Tabulator

Tabulator allows you to create interactive tables in seconds from any HTML Table, JavaScript array, AJAX data source, or JSON format data. Just include the library in your…

alert-confirm-prompt-attention-js

Simple Alert, Confirm, Prompt Popup Using Vanilla JavaScript Library | attention.js

JavaScript provides various built-in functionality to display popup messages for different purposes. Attention JS is a vanillaJS plugin used to create a custom alert, confirm, or Prompt…

Bootstrap-4-Toast-Notification-Plugin

Lightweight Bootstrap 4 Toast Notification Plugin | BS4 Advanced Toast

A lightweight Bootstrap 4 Toast Notification plugin integrated with JS/jQuery. bs4-toast.js is a JavaScript library that enhances the native Bootstrap toast component with icons, buttons, callbacks, and…

Audio-Visualizations-Wave

How to Create Audio Visualizations with JavaScript | Wave.js

Audio Visualizer Library – wave.js is a vanilla javascript audio visualization library that provides 20+ creative audio visualization effects to bring more engagement to your visitor. Contribute…

swiper-touch-slider

Modern Mobile Touch Slider With Acceleration Transitions | Swiper

Swiper is the most modern free mobile touch slider with accelerated device transitions and amazing original behavior. It is intended for use in mobile websites, mobile web…

Confetti-Falling-Animation-Effect-party

Confetti Falling Animation Effect In JavaScript | party.js

Party.js is a JavaScript library to brighten user site experience with visual effects! Celebrate success with dom confetti! The library is written in TypeScript and compiled into…

Leave a Reply

Your email address will not be published. Required fields are marked *