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

directives-vue3

v1.1.3

Published

vue3常用自定义指令

Downloads

3

Readme

directives-vue3

常用的vue3自定义指令(只提供了方法,需要自己注册指令)

Install

NPM:

npm i directives-vue3 --save

Usage

import { createApp } from "vue";
import { debounce } from 'directives-vue3'

const app = createApp(App);
app.directive("debounce", debounce)
app.mount("#app");
<script setup>
const clickFun = () => {
  console.log("点击了")
}
</script>
<template>
  <div v-debounce:500="clickFun">点击防抖函数</div>
</template>

已有的方法(注意:这里只展示了使用的参数及含义,需要自己注册指令):

1.防抖函数:debounce

使用方式:

<script setup>
const clickFun = () => {
  console.log("点击了")
}
</script>
<template>
  <div v-debounce:500="clickFun">点击防抖函数</div>
</template>

其中的500是限制的时间,单位为毫秒,可不传,默认为500

2.节流函数: throttle

使用方式:

<script setup>
const clickFun = () => {
  console.log("点击了")
}
</script>
<template>
  <div v-throttle:500="clickFun">点击节流函数</div>
</template>

其中的500是限制的时间,单位为毫秒,可不传,默认为500

3.拖拽: drag

使用方式:

<script setup>
const dragRef = ref()
const drapOptions = ref({
  x: 200,   // 弹框的初始left值
  y: 200,   // 弹框的初始top值
  targetRef: dragRef,   // 拖拽的盒子(使用ref)
  targetId: "fjdafla"   // 拖拽的盒子(使用id)
});
</script>

<template>
  <div class="dialog" v-drag="drapOptions">
    <div class="header" ref="dragRef" id="drag_box">弹框标题</div>
    <div class="main" v-debounce:1000="clickContent">内容</div>
  </div>
</template>

<style scoped>
.dialog {
  width: 300px;
  background-color: blue;
  color: #fff;
}
.header {
  height: 80px;
}
.main {
  height: 400px;
}
</style>

该指令接收一个对象作为参数,对象的可选项分别是

  • x: 元素的style的left值
  • y: 元素的style的top值
  • targetRef: 可拖拽处的元素的ref
  • targetId: 可拖拽处的元素的id

targetRef 和 targetId选其中一个就可以,也可以不传,不传默认整个使用指令的元素全部可以拖拽

4.自动获取焦点: focus

<template>
  <div><input type="text" v-focus></div>
</template>

5.文本显示省略号: ellipsis

<template>
  <div v-ellipsis:3 style="width: 200px;">这是测试文字这是测试文字这是测试文字这是测试文字这是测试文字这是测试文字这是测试文字这是测试文字这是测试文字这是测试文字这是测试文字</div>
</template>

上面的3代表3行文本显示省略号,可不传,不传默认单行文本显示省略号