Home

Awesome

<h1 align="center"> vuex-iframe-sync </h1> <p align="right" style="position:absolute;top:16px;right:28px;"> English | <a href="https://github.com/L-Chris/vuex-iframe-sync/blob/master/README.zh-CN.md">中文</a> </p> <p align="center">Vuex<strong> state synchronization</strong><em> between </em><strong> iframe/window</strong></p> <p align="center"> <a href="https://travis-ci.org/L-Chris/vuex-iframe-sync"> <img src="https://img.shields.io/travis/L-Chris/vuex-iframe-sync.svg" alt="build"> </a> <a href="https://www.npmjs.com/package/vuex-iframe-sync"> <img src="https://img.shields.io/npm/v/vuex-iframe-sync.svg" alt="npm"> </a> <a href="https://www.npmjs.com/package/vuex-iframe-sync"> <img src="https://img.shields.io/npm/dm/vuex-iframe-sync.svg" alt="downloads"> </a> </p> <p align="right"><em>Your star is the greatest encouragement to me.</em></p>

✨ Features:

🔧 Requirements

Note window.postMessage has limition on message, works like JSON.parse() and JSON.stringfy().If you have trouble with it, configure a convert function in broadcast and transfer API.

🔧 Installation

CDN

<script src="https://cdn.jsdelivr.net/npm/vuex-iframe-sync/dist/vuex-iframe-sync.umd.js"></script>

NPM

npm install vuex-iframe-sync --save

YARN

yarn add vuex-iframe-sync

📦 Examples

📦 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 change.

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:

transfer([options])

Receive state changes from parent. Send state changes to parent while self state change.

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

Build Setup

# serve with with-webpack example at localhost:8080
npm run dev

# serve with simple example at localhost:8080
npm run dev:simple

# test with jest
npm run test

# build for production with minification
npm run build

# build for production with live example
npm run build:docs

🛣 Pending

🥂 License

MIT