All Projects → cklmercer → Vue Stash

cklmercer / Vue Stash

Licence: mit
Easily share reactive data between your Vue components.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Stash

Westore
更好的小程序项目架构
Stars: ✭ 3,897 (+845.87%)
Mutual labels:  state-management
Grassbending
A replacement for Unity's terrain grass shader with alpha blended rendering and touch bending effect
Stars: ✭ 397 (-3.64%)
Mutual labels:  plugin
Oc Shopaholic Plugin
🛍️ #1 e-commerce platform for October CMS
Stars: ✭ 404 (-1.94%)
Mutual labels:  plugin
Textext
Re-editable LaTeX graphics for Inkscape
Stars: ✭ 383 (-7.04%)
Mutual labels:  plugin
Admob flutter
Admob Flutter plugin that shows banner ads using native platform views.
Stars: ✭ 390 (-5.34%)
Mutual labels:  plugin
Ucr
Universal Control Remapper [Alpha]
Stars: ✭ 399 (-3.16%)
Mutual labels:  plugin
Vue Acl
Access Control List plugin for VueJS 2.0
Stars: ✭ 376 (-8.74%)
Mutual labels:  plugin
React Recollect
State management for React
Stars: ✭ 411 (-0.24%)
Mutual labels:  state-management
Pull To Reload
Pull to reload implementation for the web. Designed to work with both mobile and websites.
Stars: ✭ 396 (-3.88%)
Mutual labels:  plugin
Chartjs Plugin Zoom
Zoom and pan plugin for Chart.js
Stars: ✭ 404 (-1.94%)
Mutual labels:  plugin
Auto re
IDA PRO auto-renaming plugin with tagging support
Stars: ✭ 388 (-5.83%)
Mutual labels:  plugin
Editormd
Markdown 编辑器 Editor.md for Typecho
Stars: ✭ 389 (-5.58%)
Mutual labels:  plugin
Klakndi
NewTek NDI™ plugin for Unity
Stars: ✭ 401 (-2.67%)
Mutual labels:  plugin
Macsubstrate
Substrate for macOS
Stars: ✭ 381 (-7.52%)
Mutual labels:  plugin
Pytest Html
Plugin for generating HTML reports for pytest results
Stars: ✭ 404 (-1.94%)
Mutual labels:  plugin
Macos headers
📚 A consistently maintained dump of most macOS Headers
Stars: ✭ 374 (-9.22%)
Mutual labels:  plugin
Ts3audiobot
Advanced Musicbot for Teamspeak 3
Stars: ✭ 397 (-3.64%)
Mutual labels:  plugin
Python Betterproto
Clean, modern, Python 3.6+ code generator & library for Protobuf 3 and async gRPC
Stars: ✭ 412 (+0%)
Mutual labels:  plugin
Elasticsearch Prometheus Exporter
Prometheus exporter plugin for Elasticsearch
Stars: ✭ 409 (-0.73%)
Mutual labels:  plugin
Dutier
The immutable, async and hybrid state management solution for Javascript applications.
Stars: ✭ 401 (-2.67%)
Mutual labels:  state-management

vue-stash

A Vue.js plugin that makes it easy to share reactive data between components.

This plugin is best suited for the rapid development of prototypes. This plugin is not intended to be used for complex applications. For complex applications I would recommend the official VueJS state management plugin, Vuex

Installation

1.) Install package via NPM
$ npm install vue-stash
2.) Install plugin within project.
import Vue from 'vue';
import VueStash from 'vue-stash';

Vue.use(VueStash)

or

window.Vue = require('vue');
require('vue-stash');

Usage

1.) Initialize your store object.

Your store object is nothing more than a simple Javascript object set within your root vue model's $data option; Think of it as your "shared data option". Make sure you pre-initialize any properties that you want to be reactive, just like always.

new Vue({
    el: '#app',
    data: {
        store: {
            user: {
                name: 'cody'
            }
        }
    }
})

Alternatively, you can import your store from another file.

import store from './store';

new Vue({
    el: '#app',
    data: { store }
})

store.js

export default {
    user: {
        name: 'cody'
    }
}
2.) Add a "store" option to any child components that need to access data from the store.

Example 1: Simplest usage

Vue.component('user-card', {
    store: ['user'],
    // Use `ready` for Vue 1.x
    mounted() {
        console.log(this.user.name); // 'cody'
        this.user.name = 'john doe';
        console.log(this.user.name); // 'john doe'
    }
});

Example 2: Object store

Vue.component('user-card', {
    store: {
        user: 'user'
    },
    // Use `ready` for Vue 1.x
    mounted() {
        console.log(this.user.name); // 'cody'
        this.user.name = 'john doe';
        console.log(this.user.name); // 'john doe'
    }
});

Example 3: Access nested store property

Vue.component('user-card', {
    store: {
        name: 'user.name'
    },
    // Use `ready` for Vue 1.x
    mounted() {
        console.log(this.name); // 'cody'
        this.name = 'john doe';
        console.log(this.name); // 'john doe'
    }
});

Example 4: Dynamic store access

Vue.component('user-card', {
    store: {
        name() {
            return 'user.name';
        }
    },
    // Use `ready` for Vue 1.x
    mounted() {
        console.log(this.name); // 'cody'
        this.name = 'john doe';
        console.log(this.name); // 'john doe'
    }
});

Note: The end result of examples 1-4 are equivalent.

3.) Access the store directly.

This plugin sets Vue.prototype.$store which allows any component to access the store via vm.$store.

Vue.component('user-card', {
    // Use `ready` for Vue 1.x
    mounted() {
        console.log(this.$store.user.name); // 'cody';
        this.$store.user.name = 'john doe';
        console.log(this.$store.user.name); // 'john doe';
    }
});

Demo

If you'd like to demo vue-stash try vue-mix

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].