@cfcs/vue2

中文文档
0.1.1发布于 2025/07/10MITTypeScriptESM + CJS近 30 天下载 2923

写入一次,创建支持React,Vue,Svelte等的框架组件.

中文使用文档
文档目录9 节
  1. Vue 2 的跨框架组件
  2. 演示 编号 : API 密码 编号 : 教学
  3. * 安装
  4. 如何使用
  5. 适配器
  6. 构成部分
  7. 应用
  8. * 反馈
  9. 许可证


Vue 2 的跨框架组件

写入一次,创建支持React,Vue,Svelte等的框架组件.

    GitHub 

演示 编号 : API 密码 编号 : 教学

* 安装

# >= 2.7
$ npm install @cfcs/vue3
# < 2.7
$ npm install @cfcs/vue2

使用 @vue/composition-api 如果你要在Vue 2中使用的话.

如何使用

Vue 2 组件可以使用 useReactive 结束 REACTIVE_ADAPTER(单位:千美元)使用 @ cfcs/ core 制作)常数.

适配器

import { reactive } from "@cfcs/core";

const REACTIVE_ADAPTER = ({
  emit,
  onInit,
  setEvents,
  setMethods,
}) => {
  setEvents(["event1"]);
  setEvents(["method1"]);

  const obj = reactive({
    value1: 1,
    method1() {
      console.log("method1");
    },
  });

  const inst = new YourModule();

  onInit(() => {
    requestAnimationFrame(() => {
      value1.current = 2;

      // emit `event1` event externally
      emit("event1", e);
    });
  });

  // Returns a reactive value.
  return obj;
};

构成部分

import { REACTIVE_ADAPTER } from "your-module";
import { useReactive, ReactiveAdapterResult } from "@cfcs/vue2";

// The result value of useReactive can be exposed as a type.
export type ReactiveComponentResult = ReactiveAdapterResult<typeof REACTIVE_ADAPTER>;

// Reactive Component can be created through useReactive.
export function useReactiveComponent(props) {
  return useReactive(REACTIVE_ADAPTER, () => props);
}

应用

<script>
export default {
  setup() {
    const {
      // state
      value1,
      // events
      onEvent1,
      // methods
      method1,
    } = useReactiveComponent({});

    // use state
    console.log(value1.value);

    // use event
    onEvent1(e => {
      console.log(e);
    };

    // use method
    method1();
  },
};
</script>

* 反馈

请存档 问题。 。 。 .

许可证

cfcs 将在 麻省理工学院许可证。 。 。 .

CFCs
Copyright (c) 2023-present NAVER Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

版本与发布记录

@cfcs/vue2 共发布 28 个版本,首次发布于 2022/07/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.1latest2025/07/101.3 年前
0.1.02023/02/243 年前
0.0.262023/02/233 年前
0.0.252023/02/233 年前
0.0.242023/02/233 年前
0.0.232023/02/233 年前

关于 @cfcs/vue2 的常见问题

@cfcs/vue2 是什么?

写入一次,创建支持React,Vue,Svelte等的框架组件.

如何安装 @cfcs/vue2?

在项目目录运行 npm install @cfcs/vue2,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@vue/composition-api(^1.2.4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cfcs/vue2 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cfcs/vue2 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cfcs/vue2 可以商用吗?

@cfcs/vue2 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cfcs/vue2 的下载量有多少?

根据 npm 官方下载统计,@cfcs/vue2 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,923 次,日均约 97 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cfcs/vue2 还在维护吗?

最新版本 0.1.1 发布于 2025/07/10(1.3 年前);至今共发布 28 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/07/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。