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

n-design-readonly-plugin

v1.0.9

Published

只读模式插件 for n-designv3

Readme

n-design-readonly-plugin

npm version npm downloads License

一个 Vue 3 高阶组件(HOC),用于将 n-designv3 表单组件一键切换为只读模式。

在业务系统中,经常需要在「编辑态」和「详情态」之间切换。本插件通过 :readonly="true" 全局控制或组件级控制,自动将 <NkInput><NkSelect> 等组件渲染为不可编辑的静态文本,无需重复编写展示逻辑。

✨ 特性

  • ✅ 支持 n-designv3 所有表单组件(Input, Select, DatePicker 等)
  • ✅ 全局控制:通过 <NkForm :readonly="true"> 一键禁用整个表单
  • ✅ 组件级控制:单个组件设置 :readonly="true"
  • ✅ 自动提取显示文本(支持 label / value 映射)
  • ✅ 完整 TypeScript 类型支持
  • ✅ 零运行时依赖(仅依赖 vuen-designv3
  • ✅ 全局控制:通过 <NkForm :copyable="false"> 一键禁用所有复制图标,默认开启
  • ✅ 组件级控制:单个组件设置 :copyable="false" 子组件配置优先级高于 <NkForm>

📦 安装

npm install n-design-readonly-plugin

1.全局注册插件

// main.ts
import { createApp } from 'vue';
import App from './App.vue';

// 引入 n-designv3(必须)
import NDesignV3 from 'n-designv3';
import 'n-designv3/dist/nancal.variable.min.css';

// 引入本插件
import NDesignReadolyPlugin from 'n-design-readonly-plugin';

const app = createApp(App);
app.use(NDesignV3);
app.use(NDesignReadolyPlugin); // 注册后自动提供 NkInput, NkSelect 等组件
app.mount('#app');

2.在模板中使用

全局只读(推荐)

<template>
  <nk-form :readonly="isReadonly" :model="form">
    <nk-form-item label="用户名">
      <nk-input v-model:value="form.name" />
    </nk-form-item>
    <nk-form-item label="城市">
      <nk-select
        v-model:value="form.city"
        :options="cityOptions"
      />
    </nk-form-item>
  </nk-form>
</template>

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

const isReadonly = ref(true);
const form = reactive({ name: '张三', city: 'bj' });
const cityOptions = [
  { label: '北京', value: 'bj' },
  { label: '上海', value: 'sh' }
];
</script>

3.组件映射

| 原始组件 (n-designv3) | 只读包装组件 | |------------------------|-------------| | <n-input> | <nk-input> | | <n-select> | <nk-select> | | <n-date-picker> | <nk-date-picker> | | ... | ... |

所有 n-* 表单组件均自动映射为 nk-*,命名规则一致。

4.工作原理

插件内部使用 provide/inject 传递 readonly 上下文 每个 nk-* 组件是 withReadonly(WrappedComponent) 的高阶封装 当 readonly === true 时,不再渲染原始组件,而是渲染一个带样式的 显示文本 文本内容通过智能解析 value + options 自动获取(如 Select 的 label)