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-mobile-tap

v1.4.0

Published

mobile tap event for vue.js

Downloads

24

Readme

mobile tap event for vue.js

Install

npm i vue-mobile-tap

Project setup

Register a global custom directive called v-tap

import Vue from 'vue'
import Tap from 'vue-mobile-tap'
Vue.use(Tap)


new Vue({
    render: h => h(App)
}).$mount('#app')

register a locally instead directive called v-tap

<script>
import { bindFunction, unbindFunction } from 'vue-mobile-tap'
export default {
    directives: {
        tap: {
            inserted: bindFunction,
            unbind: unbindFunction
        }
    }
}
</script>

Usage

Simple example

<template>
    <div id="app" v-tap="tapApp">
        <div class="btn" v-tap="tapBtn">button</div>
    </div>
</template>
<script>
export default {
    methods:{
        tapBtn(){
            console.log('I was trigger first.')
        },
        tapApp(){
            console.log('I was triggered later.')
        }
    }
}
</script>

v-tap.once

v-tap.once handler will only trigger once

<template>
    <div id="app">
        <div class="btn" v-tap.once="tapBtn">button</div>
    </div>
</template>
<script>
export default {
    methods:{
        tapBtn(){
            console.log('I trigger only once')
        }
    }
}
</script>

v-tap.stop

event.stopPropagation()

<template>
    <div id="app" v-tap="tapApp">
        <button v-tap.stop="tapBtn">click me</button>
    </div>
</template>
<script>
export default {
    methods:{
        tapBtn(){
            console.log('I was clicked.')
        },
        tapApp(){ //It will not trigger when button was clicked.
            
        }
    }
}
</script>

v-tap.prevent

event.preventDefault()

It also prevents point-through event happen | 防止点透事件触发

<template>
    <div id="app">
        <!-- bottom_div and top_div is not the parent-child relationship, but top_div show on the top of bottom_div.
        If do not prevent top_div's default touchend event, the point-through event will happen. -->
        <!-- bottom_div 和 top_div 没有父子关系, 但是 top_div 在 bottom_div 的上面显示。
        如果不阻止 top_div 的 touchend 事件,bottom_div 的 click 事件会在 top_div 消失后触发。 -->
        <div class="bottom_div" @click="clickBottom"></div>
        <div class="top_div" v-tap.prevent="tapTop" v-if="showTop">I'll hide when I'm clicked</div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            showTop: true
        }
    },
    methods:{
        tapTop(){
            this.showTop = false;
            console.log('top_div hide now.')
        },
        clickBottom(){ //It will not trigger when top_div hide.
            console.log('bottom_div was clicked')
        }
    }
}
</script>
<style>
    #app{
        position: relative;
    }
    .bottom_div{
        background: #e3e3e3;
        height: 200px;
    }
    .top_div{
        position: absolute;
        width: 72%;
        left: 14%;
        top: 75px;
        font-size: 16px;
        line-height: 50px;
        background: #0a9;
        color: #fff;
        text-align: center;
        border-radius: 3px;
    }
</style>

v-tap="[tapBtn, args...]"

Example for pass arguments

<template>
    <div id="app" v-tap="tapApp">
        <div class="btn" v-tap="[tapBtn, arg1, arg2, arg3]">button</div>
    </div>
</template>
<script>
export default {
    methods:{
        tapBtn(eventObj, arg1, arg2, arg3){
            console.log(eventObj)// {touchstartEvent: touchstartEvent, touchendEvent: touchendEvent}
        }
    }
}
</script>

Notice

when touch event is not supported, tap event handler arguments[0] is different

<template>
    <div id="app">
        <div class="btn" v-tap="tapBtn">button</div>
    </div>
</template>
<script>
export default {
    methods:{
        tapBtn(eventObj){
            console.log(eventObj) // {clickEvent: clickEvent}
        }
    }
}
</script>

Contact

The project's website is located at https://github.com/Haycher/vue-mobile-tap.git Author: Haycher, Lyu ([email protected])