Token导航 LogoToken导航TokenDH.com
前端设计只读github未标认证来源可访问许可证需确认审计通过

dynamic-components动态组件

Agent Skill

dynamic-components 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,769

周安装

76

GitHub Stars

173

下载量

620
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dynamic-components(动态组件)
来源仓库:https://github.com/patternsdev/skills
仓库路径:skills/dynamic-components
安装命令:
npx skills add https://github.com/patternsdev/skills --skill dynamic-components
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/patternsdev/skills --skill dynamic-components

简介

dynamic-components 实现基于条件渲染的动态组件切换机制,绑定 is 属性控制 <component> 显示。

  • 适用于标签页、视图切换与条件化 UI 模块加载场景。
  • 替代 v-if/v-show 提供更灵活的运行时组件管理能力。
  • 需配合路由状态或用户交互事件驱动 is 值变化。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Dynamic Components

Table of Contents

Dynamic components constitute the ability to dynamically change (i.e. switch) between components by binding an is attribute to the reserved <component> element.

We'll go through an example to best understand how dynamic components work. Assume we have separate components titled Home, Feed, and History that simply display text dictating what component it is.

When to Use

  • Use this when you need to render different components based on user interaction (e.g., tabs, views)
  • This is helpful as an alternative to multiple v-if/v-else blocks for conditional component rendering

Instructions

  • Bind the is attribute on <component> to a reactive value referencing the component definition
  • Use a tabs object mapping names to imported component definitions
  • Wrap <component> with <KeepAlive> to preserve state when switching between dynamic components

Details

<!-- Home -->
<template><div class="tab">Home component</div></template>

<!-- Feed -->
<template><div class="tab">Feed component</div></template>

<!-- History -->
<template><div class="tab">History component</div></template>

Our goal is to build an interface that surfaces a list of tabs that can be clicked. Depending on what tab is clicked, we want to dynamically render a certain component.

When clicking between the tabs, we want components to be dynamically unmounted and mounted without the use of routing. Though something like this could be achieved by conditionally rendering child templates with the help of directives like v-if and v-else, this is a perfect use case of Vue dynamic components.

In the parent App component of our app, we can first import the three individual components to have them available in the template. We'll also create a currentTab reactive property that is given an initial value of "Home".

<script setup>
  import { ref } from "vue";
  import Home from "./components/Home.vue";
  import Feed from "./components/Feed.vue";
  import History from "./components/History.vue";

  const currentTab = ref("Home");
  const tabs = {
    Home,
    Feed,
    History,
  };
</script>

Note that our tabs object references the actual component definitions and not just the component names.

In the App component template, we'll look to render three separate tab buttons — one for each component we intend to display. We'll use the v-for directive to help achieve this.

<template>
  <div class="demo">
    <button
      v-for="(_, tab) in tabs"
      :key="tab"
      :class="['tab-button', { active: currentTab === tab }]"
      @click="currentTab = tab"
    >
      {{ tab }}
    </button>
  </div>
</template>

To dynamically render a certain child component, we'll bind an is attribute to the reserved <component> element. The value attached to the is attribute should correspond to the child component that we want to render dynamically.

<template>
  <div class="demo">
    <button
      v-for="(_, tab) in tabs"
      :key="tab"
      :class="['tab-button', { active: currentTab === tab }]"
      @click="currentTab = tab"
    >
      {{ tab }}
    </button>
    <component :is="tabs[currentTab]" class="tab"></component>
  </div>
</template>

<script setup>
  import { ref } from "vue";
  import Home from "./components/Home.vue";
  import Feed from "./components/Feed.vue";
  import History from "./components/History.vue";

  const currentTab = ref("Home");

  const tabs = {
    Home,
    Feed,
    History,
  };
</script>

With the dynamic <component /> element placed in our template, the child components are now dynamically unmounted and mounted depending on which tab has been selected.

Preserving state

Preserving state can be an important consideration to keep in mind when using dynamic components. By default, when a component is unmounted, its state is lost. However, Vue provides a way to preserve the state of dynamic components using the <KeepAlive> component.

To preserve the state of dynamic components, we can wrap the <component> element with the <KeepAlive> component.

<template>
  <div class="demo">
    <!--  -->
    <KeepAlive>
      <component :is="tabs[currentTab]" class="tab"></component>
    </KeepAlive>
  </div>
</template>

<script setup>
  // ...
</script>

With the <KeepAlive> component wrapping the <component> element, the state of the dynamic components will be preserved when they are unmounted. This means that any data or component state will be maintained, and the component will retain its previous state when it is mounted again.

To see an example of this, we can update each of our child components to contain a simple counter that increments.

<!-- Repeat this counter example for Home, Feed, and History -->
<template>
  <div class="tab">
    Home component
    <p>Counter: {{ counter }}</p>
    <button @click="incrementCounter">Increment</button>
  </div>
</template>

<script setup>
  import { ref } from "vue";

  const counter = ref(0);

  const incrementCounter = () => {
    counter.value++;
  };
</script>

With these changes, the counter state for each respective child component is kept preserved even as we dynamically switch between components.

By using the <KeepAlive> component, we can enhance the behavior of dynamic components by preserving their state and providing a smoother user experience when switching between tabs.

Source

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

39.4%
按下载量换算244

Claude

28.89%
按下载量换算179

Cursor

18.92%
按下载量换算117

Gemini CLI

10.1%
按下载量换算63

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills