编写一套工具库并上传NPM

news/2024/5/20 1:18:01 标签: npm, arcgis, 前端, hooks, ts

你的 工具箱

开箱即可用的 directive\utils,
说明:vue3-directive-tools 是一个方便在 Vue 3 + Ts 项目中快速使用的 directive、tool 的 npm 插件。它允许您轻松地在项目中添加多种功能,它采用 Ts 方式开发,与 Vue3 更加搭配

npm:NPM地址
github:GitHub源码

🌍 1、安装

npm install vue3-directive-tools

说明:

此工具库是基于 Element-plus、Sass、Node、Ts,请您在安装以上依赖后使用此辅助库,它可帮您快速开发功能、您只需使用 v-xx=“” ;

🛹 2、指令的使用方法

在你的主应用程序入口文件(例如 main.js)中,导入并使用 directive :

import { directive } from "vue3-directive-tools";
app.use(directive).mount("#app");

copy

v-copy=“data”

<template>
	<div class="card content-box">
		<span class="text">复制指令 🍇🍇🍇🍓🍓🍓</span>
		<div class="box-content">
			<el-input placeholder="请输入内容" v-model="data" style="width: 500px">
				<template #append>
					<el-button v-copy="data">复制</el-button>
				</template>
			</el-input>
		</div>
	</div>
</template>

<script setup lang="ts" name="copyDirect">
import { ref } from 'vue';
const data = ref<string>('我是被复制的内容 🍒 🍉 🍊');
</script>

debounce

v-debounce=“debounceInput”

  <el-input
	v-debounce="debounceInput"
	v-model.trim="iptVal"
	placeholder="防抖输入框 (0.5秒后执行)"
	style="width: 100%"
 />

draggable

v-draggable

<template>
	<div class="content-box">
		<span class="text">拖拽指令 🍇🍇🍇🍓🍓🍓</span>
		<div v-draggable class="drag-box cursor-move">我可以拖拽哦~</div>
	</div>
</template>

<style lang="scss" scoped>
.content-box {
	position: relative; //required
	width: 500px;
	height: 500px;
	border: 1px solid #ccc;
	.drag-box {
		position: absolute; //required
		width: 100px;
		height: 100px;
		background-color: #ccc;
	}
}
</style>

longpress

v-longpress=“longpress”

<template>
	<div class="card content-box">
		<span class="text">长按指令 🍇🍇🍇🍓🍓🍓</span>
		<el-button type="primary" v-longpress="longpress"
			>长按2秒触发事件</el-button
		>
	</div>
</template>

<script setup lang="ts" name="longpressDirect">
import { ElMessage } from 'element-plus';
const longpress = () => {
	ElMessage.success('长按事件触发成功 🎉🎉🎉');
};
</script>

throttle

v-throttle=“throttleClick”

<template>
	<div class="card content-box">
		<span class="text">节流指令 🍇🍇🍇🍓🍓🍓</span>
		<el-button type="primary" v-throttle="throttleClick"
			>节流按钮 (每隔1S秒后执行)</el-button
		>
	</div>
</template>

<script setup lang="ts" name="throttleDirect">
import { ElMessage } from 'element-plus';
const throttleClick = () => {
	ElMessage.success('我是节流按钮触发的事件 🍍🍓🍌');
};
</script>

waterMarker

<div
	v-waterMarker="{text:'版权所有',textColor:'rgba(180, 180, 180, 0.4)'}"
></div>

🛹 2、utils\工具的使用方法

debounceRest

<el-button @click="handClick('我是参数')">首页</el-button>

import { debounceRest } from "vue3-directive-tools";

const handClick = debounceRest((varStr: string) => {
	console.log("!这里输出防抖 🚀 ==>:", varStr);
}, 250);

isEvenOrOdd

<el-button @click="handClick">判断奇数偶数</el-button>
import { isEvenOrOdd } from "vue3-directive-tools";

function handClick() {
	const isEvenOrOdd = isEvenOrOdd(123);
	console.log("!这里输出奇偶判断 🚀 ==>:", isEvenOrOdd);
}

npm__169">1、npm 命令大全

以下是一些常见的 npm 命令:

  1. 初始化一个新的 npm 项目:npm init
  2. 安装依赖库:npm install <package-name>
  3. 全局安装依赖库:npm install -g <package-name>
  4. 更新依赖库:npm update <package-name>
  5. 删除依赖库:npm uninstall <package-name>
  6. 运行脚本:npm run <script-name>
  7. 显示当前项目的依赖列表:npm ls
  8. 查看特定依赖库的信息:npm view <package-name>
  9. 搜索依赖库:npm search <keyword>
  10. 发布包到 npm 仓库:npm publish

当使用 npm install 命令时,可以添加一些标志来指定依赖包的安装方式:

  1. -S,或者 --save:将依赖项添加到 dependencies(生产环境依赖)中。
    示例:npm install <package-name> -S

    npm install <package-name> --save

  2. -D,或者 --save-dev:将依赖项添加到 devDependencies(开发环境依赖)中。
    示例:npm install <package-name> -D

    npm install <package-name> --save-dev

npm__196">2、切换 npm 源:

要切换到官方源,可以执行以下命令:

npm config set registry https://registry.npmjs.org/

要切换到淘宝源,可以执行以下命令:

npm config set registry https://registry.npm.taobao.org/

要切换到 cnpm 源,可以执行以下命令:

npm config set registry http://r.cnpmjs.org/

验证切换结果:执行以下命令可以验证切换的结果

npm config get registry

3、发布为公共包

使用以下命令发布为公共包:

npm publish --access=public

npm__230">4、修改 npm

修改完包代码后,可以执行以下命令将版本号自动加 1:

npm version patch

或者您也可以手动修改package.json文件中的版本号,然后执行npm publish来发布修改后的包。

修改并发布完成。

npm__242">5、删除 npm

要删除特定版本的包,可以使用以下命令:

npm unpublish 包名@版本号

要强制删除所有版本的包,可以使用以下命令:

npm unpublish 包名 --force

http://www.niftyadmin.cn/n/4936035.html

相关文章

41 | 京东商家书籍评论数据分析

京东作为中国领先的电子商务平台,积累了大量商品评论数据,这些数据蕴含了丰富的信息。通过文本数据分析,我们可以了解用户对产品的态度、评价的关键词、消费者的需求等,从而有助于商家优化产品和服务,以及消费者作出更明智的购买决策。 本文将详细阐述如何获取京东商家评…

分支语句与循环语句(2)

3.3 do...while()循环 3.3.1 do语句的语法&#xff1a; do 循环语句; while(表达式); 3.3.2执行流程图&#xff1a; 3.3.3 do语句的特点 循环至少执行一次&#xff0c;使用的场景有限&#xff0c;所以不是经常使用。 打印1-10的整数&#xff1a; #define _CRT_SECURE_NO_WA…

树的遍历经典机试题目(已知中序和先序,求后序)的两种做法

方法一、建树&#xff0c;再dfs搜&#xff08;已知中序和先序&#xff0c;求后序&#xff09; P1827 [USACO3.4] 美国血统 American Heritage #include <bits/stdc.h> using namespace std; char first; int length; string preorder, inorder; //a[1][C]B, 表示C的左儿…

postgresql字段被截断问题

前言 最近遇到一个问题就是字段名过长&#xff0c;会被pg给截断&#xff0c;导致原始字段和下游用的的字段不一样&#xff0c;就会报错。当然&#xff0c;小伙伴可能会说为什么会用那么长的字段名&#xff0c;每个应用程序里面处理不一样&#xff0c;我们数据字段每次被使用就…

实训五:用户和组账号管理

实训五&#xff1a;用户和组账号管理 2017 年 X 月 X 日 今日公布 四&#xff1a;实训内容 用root用户登录系统&#xff0c;查看用户账号文件/etc/passwd和口令文件/etc/shadow的内容&#xff0c;注意观察其存储格式、各账户所使用的Shell、UID、GID等属性信息。 答&#xf…

【Spring Cloud +Vue+UniApp】智慧建筑工地平台源码

智慧工地源码 、智慧工地云平台源码、 智慧建筑源码支持私有化部署&#xff0c;提供SaaS硬件设备运维全套服务。 前言&#xff1a;互联网建筑工地&#xff0c;是将互联网的理念和技术引入建筑工地&#xff0c;从施工现场源头抓起&#xff0c;最大程度的收集人员、安全、环境、材…

五、 离线推荐数据缓存

五 离线推荐数据缓存 5.1离线数据缓存之离线召回集 这里主要是利用我们前面训练的ALS模型进行协同过滤召回&#xff0c;但是注意&#xff0c;我们ALS模型召回的是用户最感兴趣的类别&#xff0c;而我们需要的是用户可能感兴趣的广告的集合&#xff0c;因此我们还需要根据召回的…

div 中元素居中的N种常用方法

本文主要记录几种常用的div盒子水平垂直都居中的方法。本文主要参考了该篇博文并实践加以记录说明以加深理解记忆 css之div盒子居中常用方法大全 本文例子使用的 html body结构下的div 盒子模型如下&#xff1a; <body><div class"container"><div c…