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-pandora-decorators

v1.1.2

Published

vue3.0 decorators

Downloads

7

Readme

Vue Pandora Decorators

  • npm i vue-pandora-decorators --save
  • yarn add vue-pandora-decorators

本插件基于 VUE 3.0 开发

  • vuex 修饰器及 Composition API 支持
  • 面向对象 @Component 支持 使用vue-class-component
  • 本插件主要是用 Proxy 代理模式 代理 Vue Context

基础使用

vuex 修饰器使用

  • 全局 dynamic 模式
  • 入口 store/index.ts
import { createStore } from 'vuex';
import { PermissionState } from './modules/permission';

export interface IRootState {
    permission: PermissionState;
}

export default createStore<IRootState>({});
  • store/modules/permission.ts

import { VuexModule, Module, Action, Mutation, getModule } from 'vue-pandora-decorators';
import store from '/@/store';

export interface PermissionState {
    sessiontoken: string;
    freshtoken: string;
    roles: string[];
}

@Module({ dynamic: true, store, name: 'permission' })
class Permission extends VuexModule implements PermissionState {
    public sessiontoken: string;
    public freshtoken: string;
    public roles: string[];

    constructor(props: any) {
        super(props);
        this.sessiontoken = sessionStorage.getItem('sessiontoken') || '';
        this.freshtoken = sessionStorage.getItem('freshtoken') || '';
        this.roles = [];
        // this.routes = constantRoutes.concat(asyncRoutes);
        // this.dynamicRoutes = asyncRoutes;
    }

    @Action
    public test(roles: string[]) {
        console.log(this);
        return this.setTest(roles);
    }

    @Mutation
    private setTest(roles: string[]) {
        console.log(roles);
        this.roles = roles;
        return roles;
    }

    // @Action
    // public generateRoutes(roles: string[]) {
    //     let accessedRoutes = filterAsyncRoutes(asyncRoutes, roles);
    //     this.settingRoutes(accessedRoutes);
    // }

    // @Mutation
    // private settingRoutes(routes: RouteConfig[]) {
    //     this.routes = constantRoutes.concat(routes);
    //     this.dynamicRoutes = routes;
    // }
}

export const PermissionModule = getModule(Permission);
  • 模块化异步使用 在模块中异步 注入
  • 如 layout/store.ts
import { VuexModule, Module, Action, Mutation } from 'vue-pandora-decorators';
import store from '/@/store';

export interface LayoutState {
    testObj: {
        name: string;
        test?: { name: string; }
    };
}

@Module({ store })
export class Layout extends VuexModule implements LayoutState {
    public testObj: { name: string; };

    constructor(props: any) {
        super(props);
        this.testObj = { name: '111' };
    }

    @Action({ commit: 'testActionSuccess' })
    public testAction(obj: string[]) {
        return obj;
    }

    @Mutation
    protected testActionSuccess(obj: string[]) {
        this.testObj = { ...this.testObj, [(new Date).getTime()]: obj };
        return this.testObj;
    }
}
  • layout/layout.vue
<template>
    <div>
        <div>{{ roles }}</div>
        <div>{{ computed }}</div>
        <el-button @click="() => test(['1', '2', '3'])">Test</el-button>
        <div>{{ testObj }}</div>
        <el-button @click="editObj">Action</el-button>
    </div>
    <router-view />
</template>
<script lang="ts">
import { Component, Vue, useAction, useState } from 'vue-pandora-decorators';
import { PermissionModule } from '../store/modules/permission';
import { Layout, LayoutState } from './store';

@Component
export default class extends Vue {

    public get roles() {
        return PermissionModule.roles;
    }

    public get computed() {
        return `${(new Date).getTime()}${(PermissionModule.roles).join('')}`;
    }

    public get test() {
        return PermissionModule.test;
    };

    public get testObj() {
        return useState<LayoutState>(Layout).testObj;
    }

    public get editObj() {
        return useAction(Layout).testAction;
    }

    constructor() {
        super(arguments);
        // console.log(this.roles);
    }
}
</script>
  • 也可以这么使用 随便一个 vue 文件
<template>
    <div>
        <div>{{roles}}</div>
        <el-button @click="() => test(['1','2','3'])">Test</el-button>
    </div>
</template>
<script lang="ts">
import { computed, defineComponent } from 'vue';
import { PermissionModule } from '../store/modules/permission';
export default defineComponent({
    setup() {
        return {
            roles: computed(() => PermissionModule.roles),
            test: PermissionModule.test,
        };
    }
})
</script>

在最后感谢一下 vuex-module-decorators

在最后感谢一下 vue-class-component

  • 这里偷懒直接使用大佬的 库 十分感谢
  • 后续迭代更多 需要支持的 API
  • 最后再提一嘴 VUE 3.0 深入理解后确实不错 一开始看到 这意大利面条真心没胃口
  • 但经过思想斗争后 开始 开发这个插件 写到后面发现 面向对象与 Composition API 可以擦出别样的火花
  • 感谢尤大大
  • 请根据自己喜好食用 ✌️