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

vue-role-text

v1.0.1

Published

Vue 2 plugin to render text by role type, similar to i18n

Downloads

351

Readme

role-text

Vue 2 插件,根据当前角色类型渲染对应文案,用法类似 i18n。

安装

import RoleTextPlugin from './src'

Vue.use(RoleTextPlugin, {
  messages: {
    admin: {
      welcome: '管理员你好',
      title:   '管理后台',
    },
    user: {
      welcome: '用户你好',
      title:   '首页',
    },
  },
})

messages 的顶层 key 为角色类型,每个角色下的 key/value 为文案条目。同一个 key 在不同角色下返回不同的值。

设置角色

登录后调用 setRole 设置当前角色,全局响应式生效:

// 登录成功后
this.$rt.setRole('admin')

切换角色后,所有使用 $rt 的地方自动更新。

获取文案

在模板中

<p>{{ $rt('welcome') }}</p>
<p>{{ $rt('title') }}</p>

在 JS 中

const text = this.$rt('welcome')

key 不存在时,直接返回 key 本身,不会报错。

role-text 组件

插件注册了全局组件 <role-text>,可替代函数调用方式:

<!-- 默认渲染为 <span> -->
<role-text msg-key="welcome" />

<!-- 通过 tag 指定渲染标签 -->
<role-text msg-key="title" tag="h1" />
<role-text msg-key="welcome" tag="p" />

Props

| Prop | 类型 | 必填 | 默认值 | 说明 | |-----------|--------|------|----------|--------------| | msg-key | String | 是 | — | 文案的 key | | tag | String | 否 | 'span' | 渲染的 HTML 标签 |

运行时替换文案

如需在运行时整体替换文案(例如从接口拉取),使用 setMessages

const messages = await fetchMessages()
this.$rt.setMessages(messages)

API 速查

| 调用方式 | 说明 | |---------------------------------|----------------------------| | Vue.use(plugin, { messages }) | 安装插件并传入文案 | | this.$rt('key') | 获取当前角色对应的文案 | | this.$rt.setRole('roleName') | 设置当前角色 | | this.$rt.setMessages(obj) | 运行时替换全量文案 |