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-hook-directive

v0.1.6

Published

Plugin for vue, which integrates features from hookable to vue directives and composable

Downloads

5

Readme

Vue Hook Directive

The Vue Hook Directive is a powerful Vue plugin that seamlessly integrates features from the hookable library into Vue directives and composables, enabling you to harness the full potential of hooks within your Vue applications.

Installation

You can easily install the Vue Hook Directive using your preferred package manager:

Using npm:

npm install vue-hook-directive

Using yarn:

yarn add vue-hook-directive

Using pnpm:

pnpm add vue-hook-directive

Why Choose This Library?

There are several compelling reasons to utilize this library in your Vue projects:

  1. Cross-Component Hooks: You can utilize hooks across different components effortlessly. For instance:
<!-- MyFirstComponent.vue -->
<template>
  <button v-hook:click.expand>Click on me</button>
</template>
  1. Flexible Hook Names: Hooks can be assigned names to enable fine-grained control. If a hook name isn't specified, the default hook name will be the associated event name (e.g., 'click' for a click event).

  2. Dynamic Hook Usage: Hooks can be accessed dynamically using the $hook function and a specific hook name:

<!-- MySecondComponent.vue -->
<template>
  <div class="card" v-if="$hook('expand')">Showed</div>
</template>

Plugin Functionality

Composable Usage

The Vue Hook Directive offers a composable API:

import { useHook } from 'vue-hook-directive';

const { hook, callHook } = useHook();

hook('expand', (data) => {
    console.log(data || true);
});

Global Function $hook

You can utilize the global $hook function to integrate hooks into various Vue directives:


<template>
  {{ $hook('hook_name') }}
  <!--  Can be used as  -->
  <div v-if="$hook('hook_name')"></div>
  <div v-show="$hook('hook_name')"></div>
  <!--  And etc all build in vue hooks...  -->
  <div v-for="hook in $hook('hook_name')"></div>

  <!--  Also $hook have options -->
  <!--  Clears hook result after 1000ms -->
  {{ $hook('hook_name', {clear: 1000}) }}

  <!--  Clears hook result after 1000ms, and set default value 'something' -->
  {{ $hook('hook_name', {clear: 1000, default: 'something'}) }}

  <!--  Just set default value instead of null -->
  {{ $hook('hook_name', {default: 'something'}) }}
</template>

Directive

Directive usage, v-hook:event_name.hook_name="value""

<template>
<!--  Simple usage  -->
   <button v-hook:click.expand>Click to expand</button>
<!--  Usage with value  -->
   <button v-hook:click.expand="'any value, object and etc...'">Click to expand</button>
<!--   Usage with .toggle  -->
   <button v-hook:click.expand.toggle>Click to expand</button>
<!--   .toggle toggles boolean value (true - false)  -->
   <div v-if="$hook('expand')">
      Toggle view
   </div>
<!--   Usage with several hooks name  -->
   <button v-hook:click.expand.expand2.expand3.etc>Click to expand</button>
<!--   with .toggle-->
   <button v-hook:click.expand.expand2.expand3.toggle>Click to expand</button>
</template>

Usage

Basic Usage

To incorporate the Vue Hook Directive into your application:

import { createApp } from 'vue';
import App from './App.vue';
import { vueDirective } from 'vue-hook-directive';

const app = createApp(App);

app.use(vueDirective, {});

app.mount('#app');

Usage with Options

You can customize the behavior of the Vue Hook Directive by passing options:

app.use(vueDirective, {
    prefix: '', // Adds a prefix before hooks
    listeners: ['your-custom-listener'] // Add your custom listeners for v-hook directive
});

Usage with Nuxt

In a Nuxt application, you can follow these steps:

  1. Create a file named VueHookDirective.js within the /plugins directory in your Nuxt app.
  2. In VueHookDirective.js, import and apply the Vue Hook Directive:
import { vueDirective } from 'vue-hook-directive';

export default defineNuxtPlugin((nuxtApp) => {
    nuxtApp.vueApp.use(vueDirective);
    
    // or with options
    
    nuxtApp.vueApp.use(vueDirective, {
        prefix: '', // Adds a prefix before hooks
        listeners: ['your-custom-listener'] // Add your custom listeners for v-hook directive
    });
});

By following these steps, you can seamlessly integrate the Vue Hook Directive into your Nuxt project.

Harness the power of hooks and enhance your Vue applications with the Vue Hook Directive!