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-dynamic-components

v1.0.17

Published

Vue dynamic components plugin

Downloads

9

Readme

Vue dynamic components

Vue3 only now

See online demo

See demo project repository

See demo project codesandbox

Table of Contents

Install

$ npm install vue-dynamic-components --save

$ yarn add vue-dynamic-components

Configuration

import Vue from "vue";
import VueDynamicComponents from "vue-dynamic-components";
Vue.use(VueDynamicComponents);

Easy start

  1. Add the <dynamic-components-wrapper /> where you want (as default to root in App.vue)
  2. Where you want import needed vue component
  3. Call this.$dc.push(YourVueComponent);
  4. All components called from push has $hide() method, use it of emit('hide') for close your component from it.

Push method

push(component, options, wrapperName) Name | Type | Description | | ------------- | ------------- | ------------ | - component | Vue component | Your imported Vue component | Required options | Object | wrapperName | String | The name of the wrapper in which you want to display the component

Options object

| Property name | Type | Descrition | | ------------- | ------ | ----------------------------------------------------------------------------------- | | props | Object | Props that will be passed to your component | | events | Object | Event handlers that will be passed to your component | | queue | String | If you want your components to appear in turn, specify the queue | | type | String | If you want the same components not to appear multiple times, specify the same type | | animation | String | Each component is wrapped in a transition tag, name the animation if you want | | refs | Array | If you want to close component use refs to get id |

Hide method

hide(id, wrapperName) Name | Type | Description | | ------------- | ------------- | ------------ | - id | Number | Component unique id, use object.refs to get it | Required wrapperName | String | The name of the wrapper which displays the component

Named wrappers

Use <dynamic-components-wrapper name="wrapperName"/>

Cases

Use different wrappers for toast and modals

App.vue

<template>
  <div id="app">
    <button @click="showToast">Show toast</button>
    <button @click="showModal">Show modal</button>
    <dynamic-components-wrapper name="modals" class="modals-wrapper-class" />
    <dynamic-components-wrapper name="toasts" class="toasts-wrapper-class" />
  </div>
</template>
import ToastComponent from "@/components/ToastComponent";
import ModalComponent from "@/components/ModalComponent";

export default {
  methods: {
    showToast() {
      this.$dc.push(ToastComponent, {}, "toasts");
    },
    showModal() {
      this.$dc.push(ModalComponent, {}, "modals");
    },
  },
};

Use refs for hiding showed modals

App.vue

<template>
  <div id="app">
    <button @click="showModal">Show modal</button>
    <button @click="hideAllModal">Hide modals</button>
    <dynamic-components-wrapper />
  </div>
</template>
import ModalComponent from "@/components/ModalComponent";

export default {
  data() {
    return {
      modals: [],
    };
  },
  methods: {
    showModal() {
      this.$dc.push(ModalComponent, { refs: this.modals });
    },
    hideAllModal() {
      this.modals.forEach((modal) => {
        this.$dc.hide(modal.id);
      });
    },
  },
};

Use props, events, queue and animation

App.vue

<template>
  <div id="app">
    <button @click="showModal">Show modal</button>
    <dynamic-components-wrapper />
  </div>
</template>
import ModalComponent from "@/components/ModalComponent";

export default {
  methods: {
    showModal() {
      this.$dc.push(ModalComponent, {
        props: { text: "Dynamic modal" },
        events: {
          selected(value) {
            console.log(value);
          },
        },
        queue: "modals",
        animation: "fade",
      });
    },
  },
};
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}

.fade-enter,
.fade-leave-to {
  opacity: 0;
}

For example modal component

ModalComponent.vue

<template>
  <div class="wrapper" @click.self="$hide()">
    <div class="dialog">
      <div>{{ text }}</div>
      <div>
        <button @click="$emit('selected', true)">Yes</button>
        <button @click="$emit('selected', false)">No</button>
      </div>
    </div>
  </div>
</template>
export default {
  props: {
    text: {
      type: String,
      default: "Dynamic component",
    },
  },
};
<style scoped>
.wrapper {
    left: 0;
    top: 0;
    position: fixed;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.dialog {
    width: 300px;
    height: 300px;
    border-radius: 5px;
    cursor: default;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
</style>