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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue3-encryption-plugin

v1.0.8

Published

✈️🔖🔖 pinia插件加密、实现本地数据加密解密

Readme

你的 Pinia 加密插件

你的 Pinia 加密插件是一个基于 crypto-js 封装的实用hooks工具,用于在 Vue.js 应用程序中加密和解密敏感数据。它提供了一种简单且安全的方式来保护你的数据。

🌍 安装

你可以使用 npm 或 yarn 安装插件:

pnpm i vue3-encryption-plugin

🛹 使用方法

在你的主应用程序入口文件(例如 main.js)中,导入并使用 Pinia store 以及加密插件:

// main.js
import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
// 引入加密插件
import EncryptionPlugin from "vue3-encryption-plugin";

const app = createApp(App);

const pinia = createPinia();
app.use(pinia);

// 注册加密插件并提供自定义的密钥(可选)例如,随机的字符串
app.use(EncryptionPlugin, { key: "your-custom-secret-key" });

app.mount("#app");

🤖 加密和解密

一旦你设置了插件,你就可以在组件中使用 $encrypt 和 $decrypt 方法:

第一种: getCurrentInstance()

<!-- YourComponent.vue -->
  import {  getCurrentInstance } from 'vue';
  setup(){
     // 获取当前组件的上下文,下面两种方式都能获取到组件的上下文。
     const { ctx }  = getCurrentInstance();  //  方式一,这种方式只能在开发环境下使用,生产环境 下的ctx将访问不到
     const { proxy }: any = getCurrentInstance();  //  方式二,此方法在开发环境以及生产环境下都能到组件上下文对象(推荐)
     // ctx 中包含了组件中由ref和reactive创建的响应式数据对象,以及以下对象及方法;
     proxy.$attrs
     proxy.$data
     proxy.$el
     proxy.$emit
     proxy.$forceUpdate
     proxy.$nextTick
     proxy.$options
     proxy.$parent
     proxy.$props
     proxy.$refs
     proxy.$root
     proxy.$slots
     proxy.$watch
  }

function handClick() {
	console.log(
		"加密 🚀 ==>:",
		proxy.$encryptionPlugin.encrypt({ name: "zk", age: 26})
	);
	console.log(
		"解密 🚀 ==>:",
		proxy.$encryptionPlugin.decrypt(
			"U2FsdGVkX1/PBDHn2pyLPAf6DmolvylM2QEIDhcf5I3WQWhOh19eos0uZfdbzdDP"
		)
	);
}

第二种 injict (推荐)

1:src / types / global.d.ts 定义类型

// 加密解密
declare interface EncryptionPlugin {
	encryptData: <T>(data: T) => string;
	decryptData: <T>(encryptedData: string) => T;
}

如果你使用 eslint 请在 .eslintrc.cjs 文件中添加

	globals: {
		// 以下是全局变量 eslint 不会报'EncryptionPlugin' is not defined.eslint (no-undef)
		EncryptionPlugin: "readonly",
         $encryptionPlugin: "readonly",
	},

2: 页面使用

<script setup lang="ts">
import { inject } from 'vue';

// 使用 inject 函数获取 encryptionPlugin
const encryptionPlugin = inject("encryptionPlugin") as EncryptionPlugin;

function handClick() {
	// 现在你可以在你的组件中使用 encryptData 和 decryptData 方法了
	const encryptedData = encryptionPlugin.encryptData("Hello World");
	const decryptedData = encryptionPlugin.decryptData(encryptedData);
	console.log("加密 🚀 ==>:", encryptedData);
	console.log("解密 🚀 ==>:", decryptedData);
}
</script>