npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-context-data

v0.1.2

Published

Vue context, used for vue generation components to synchronize data data, similar to the context function of react

Downloads

8

Readme

vue-context-data

React context for vue, mainly used for data communication between father component and son component. The main function of this vue plugin is to communicate between parent and child, not just to simulate react mainly to solve the following two problems.

  1. Simple application simplifies the sharing of parent and child component communication and the sharing and change of the same data without introducing vuex (vuex can really manage the data and state of the application well, but in fact the development cost of maintaining the store is relatively high, Simple application or simple module data. The introduction of complex data management in closed applications is not necessarily a good choice.
  2. The decoupling between the component between the business component and the common component under vuex and vuex (sorry, I prefer the method of connect-react-redux for data binding, vuex officially recommended calling mode for business data The components that are processed, but at the same time versatile components are not particularly friendly, and the way to introduce and distribute is easy to couple components with vuex)

Installation

npm install vue-context-data --save

Basic use

Global registration vue-context-data

import VueContextData from 'vue-context-data';

Vue.use(VueContextData);

The parent component declares Context Data via context

export default {
    name: 'u-main',
    context: {
        nodes: Array,
        instance: Object,
    },
    data() {
        return {
            type: 0,
        };
    },
    created() {
        this.instance = {
            name: 'test',
        };
    },
}

The child component declares the accepted context data type through contextTypes, and declares that the context will automatically bind the context in the parent component of the most recent and declared context.

export default {
    contextTypes: {
        nodes: Array,
        instance: Object
    },
}

Set default value

The vue-context-data property setting refers to the props of vue, allowing the user to set the default value. If the parent of the child component does not set the value in the context data, the default value will automatically fill the default declared in the contextTypes. At the same time, if the parent component's context declares value, it will be automatically populated at initialization time. a context declaration in the parent component

export default {
    name: 'u-main',
    context: {
        nodes: Array,
        instance: {
            type: Object,
            value: {
                name: 'test',
            }
        }
    },
    data() {
        return {
            type: 0,
        };
    },
}

a contextTypes declaration in a child component

export default {
    contextTypes: {
        nodes: Array,
        instance: {
            type: Object,
            dafault: {
                name: 'test',
            }
        }
    },
    created() {
        console.log(this.nodes);
    }
}

Custom selection parent node

a context declaration in the parent component

export default {
    name: 'u-main',
    context: {
        nodes: Array,
        instance: {
            type: Object,
            value: {
                name: 'test',
            }
        }
    },
    data() {
        return {
            type: 0,
        };
    },
}

a contextTypes declaration in a child component

export default {
    contextTypes: {
        nodes: Array,
        instance: {
            type: Object,
            dafault: {
                name: 'test',
            },
            parent(dom) {
                return dom.$options.name === 'u-main';
            },
        }
    },
    created() {
        console.log(this.instance);
    }
}

Changelog

See Releases

Suggestions and bugs

See Releases

License

See LICENSE