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

@deppon/deppon-pinia

v2.2.1

Published

Pinia state management wrapper package

Readme

@deppon/deppon-pinia

Pinia 状态管理封装包,提供统一的 Pinia 配置和便捷的使用方式。

安装

npm install @deppon/deppon-pinia

依赖说明

  • pinia 已声明为 peerDependencies,如果宿主项目已安装 pinia@^2.1.7,将优先使用宿主项目的版本,避免版本冲突
  • 如果宿主项目未安装 pinia,会自动安装(因为也在 dependencies 中)
  • 建议宿主项目显式安装 pinia@^2.1.7 以确保版本一致性

特性

  • 🎯 统一的 Pinia 配置管理
  • 📊 集成状态变更日志追踪(可选)
  • 🔌 支持 Vue 3 Composition API 和 Options API
  • 🎨 提供便捷的 composable 函数
  • 📦 轻量级封装,不改变 Pinia 原有 API

基础使用

1. 安装插件

在 Vue 应用中安装插件:

import { createApp } from 'vue';
import { default as VuePlugin } from '@deppon/deppon-pinia';

const app = createApp(App);

// 基础安装
app.use(VuePlugin);

app.mount('#app');

2. 创建 Store

// stores/user.js
// 推荐:从 @deppon/deppon-pinia 导入
import { defineStore } from '@deppon/deppon-pinia';

// 或者从 pinia 导入(也支持)
// import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
    state: () => ({
        name: '',
        age: 0,
    }),
    getters: {
        displayName: state => {
            return state.name || '未命名';
        },
    },
    actions: {
        setName(name) {
            this.name = name;
        },
        setAge(age) {
            this.age = age;
        },
    },
});

3. 在组件中使用

Composition API

<script setup>
import { useUserStore } from '@/stores/user';
import { storeToRefs } from '@deppon/deppon-pinia';

const userStore = useUserStore();
const { name, age } = storeToRefs(userStore);

const handleUpdate = () => {
    userStore.setName('张三');
    userStore.setAge(25);
};
</script>

<template>
    <div>
        <p>姓名: {{ name }}</p>
        <p>年龄: {{ age }}</p>
        <button @click="handleUpdate">更新</button>
    </div>
</template>

Options API

<script>
import { useUserStore } from '@/stores/user';

export default {
    computed: {
        ...mapState(useUserStore, ['name', 'age']),
    },
    methods: {
        ...mapActions(useUserStore, ['setName', 'setAge']),
        handleUpdate() {
            this.setName('张三');
            this.setAge(25);
        },
    },
};
</script>

高级配置

集成日志追踪

如果需要在状态变更时进行埋点追踪,可以传入日志实例:

import { createApp } from 'vue';
import { default as VuePlugin } from '@deppon/deppon-pinia';
import { useLog } from '@deppon/deppon-log';

const app = createApp(App);
const log = useLog();

// 安装插件并配置日志追踪
app.use(VuePlugin, {
    log: log,
});

app.mount('#app');

配置后,每次状态变更都会自动触发日志事件 pinia_state_change

使用 createDepponPinia 创建自定义实例

如果需要更精细的控制,可以直接使用 createDepponPinia

import { createApp } from 'vue';
import { createDepponPinia } from '@deppon/deppon-pinia';
import { useLog } from '@deppon/deppon-log';

const app = createApp(App);
const log = useLog();

const pinia = createDepponPinia({
    log: log,
    beforeCreate: store => {
        console.log('Store 创建前:', store.$id);
    },
    afterCreate: store => {
        console.log('Store 创建后:', store.$id);
    },
});

app.use(pinia);
app.mount('#app');

使用 usePinia 获取实例

import { usePinia } from '@deppon/deppon-pinia';

export default {
    setup() {
        const pinia = usePinia();

        // 访问所有 stores
        console.log(pinia.state.value);

        return {};
    },
};

API

Vue 插件

  • VuePlugin - Vue 插件,用于安装到 Vue 应用

核心函数

  • createDepponPinia(options) - 创建增强的 Pinia 实例
    • options.log - 日志实例(可选)
    • options.beforeCreate - Store 创建前的钩子函数(可选)
    • options.afterCreate - Store 创建后的钩子函数(可选)

Composition API

  • usePinia() - 获取 Pinia 实例
  • useStore(store) - 使用 Store(等同于 Pinia 的 useStore
  • storeToRefs(store) - 将 Store 转换为 refs(等同于 Pinia 的 storeToRefs

Options API

  • this.$pinia - 访问 Pinia 实例(需要安装插件)

持久化存储

如果需要持久化存储功能,建议使用 pinia-plugin-persistedstate

npm install pinia-plugin-persistedstate
import { createPinia } from 'pinia';
import { createPersistedState } from 'pinia-plugin-persistedstate';

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

app.use(pinia);

注意事项

  1. 本包是对 Pinia 的轻量级封装,不会改变 Pinia 的原有 API
  2. 所有 Pinia 的原生功能都可以正常使用
  3. 日志追踪功能是可选的,需要传入日志实例才会生效
  4. 建议在项目入口文件中统一安装插件,确保全局可用

更多信息