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-hump

v0.0.1

Published

Utility to mount Vue 3 apps into existing markup. Supports passing props via HTML attributes, without using the template compiler.

Downloads

2

Readme

vue-hump

Tiny utility to mount Vue 3 apps into existing markup. Supports passing props via HTML attributes, without using the template compiler.

This is useful when using Vue to augment a traditional server-side application, like WordPress.

Getting Started

Simply install via NPM, or your favourite package manager:

npm i vue-hump

Then import the ES module:

import { mountAll } from 'vue-hump';

Examples

Simple Example

We can mount a fictional component LikeCounter to all .like-counter elements:

<div class="like-counter"></div>
import { mountAll } from 'vue-hump';
import LikeCounter from 'LikeCounter.vue';

mountAll(LikeCounter, '.like-counter');

Passing Props via data-*

We could pass an ID or any number of other properties to our fictional LikeCounter. All we need to do is set a data-* attribute on the element, and the prop will be available to Vue:

<div class='like-counter' data-content-id='500'></div>

contentId is now available as a prop in the component.

Passing JSON objects as props via data-*:json

We can also pass a JSON object as a data-* prop, by using the special syntax :json:

<div class='like-counter' data-my-object:json='{"foo": "bar"}'></div>

myObject is now available as a prop in the component, and is an object.

Accessing inner HTML content

Inner html content is automatically exposed as the inner property.

<div class="like-counter">This text will be available as a string on the `inner` prop!</div>

Loading Vue plugins

You can pass an array of plugins as an optional last parameter to any of the mount functions:

import { mountAll } from 'vue-hump';
import MyPlugin from 'my-plugin';
import LikeCounter from 'LikeCounter.vue';

mountAll(LikeCounter, '.like-counter', MyPlugin);

... Or pass plugin options via a nested array:

import { mountAll } from 'vue-hump';
import MyPlugin from 'my-plugin';
import LikeCounter from 'LikeCounter.vue';

mountAll(LikeCounter, '.like-counter', [[MyPlugin, {myOption: true, otherOption: false}]);

... Or multiple plugins (with or without options!)

import { mountAll } from 'vue-hump';
import MyPlugin from 'my-plugin';
import MyOtherPlugin from 'my-other-plugin';
import LikeCounter from 'LikeCounter.vue';

mountAll(LikeCounter, '.like-counter', [MyOtherPlugin, [MyPlugin, {myOption: true, otherOption: false}]);

API

mountAll

Mounts a Vue component to all elements matching a selector.

function mountAll(component: Component, selector: string, uses: Plugin[] | Plugin = []): Component[]

component: Component

Your Vue component object.

selector: string

A DOM selector string to target elements. If more than one match is found, a new instance will be created for each.

uses: Plugin[] | Plugin = []

A single Vue plugin, or array of Vue plugin objects. If you need to pass options to the plugins, you can use a nested array. For example: [[MyPlugin, {myOption: true, otherOption: false}], MyOtherPlugin, ...]

mountElement

Mounts a Vue component to a single HTML element.

function mountElement(component: Component, el: HTMLElement, uses: Plugin[] | Plugin = []): Component

component: Component

Your Vue component object.

el: HTMLElement

Your HTMLElement to mount the component to.

uses: Plugin[] | Plugin = []

A single Vue plugin, or array of Vue plugin objects. If you need to pass options to the plugins, you can use a nested array. For example: [[MyPlugin, {myOption: true, otherOption: false}], MyOtherPlugin, ...]