@wc-kit/vue 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @wc-kit/vue
2
+
3
+ Vue 3 适配包:为 [@wc-kit/core](../core) 的 Web Components 提供 **模板类型检查**(GlobalComponents 增强)。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add @wc-kit/vue vue
9
+ ```
10
+
11
+ ```ts
12
+ // main.ts —— 副作用导入注册全部自定义元素
13
+ import '@wc-kit/vue';
14
+ ```
15
+
16
+ ## 类型增强
17
+
18
+ 引入本包后,SFC 模板中的 `<wc-*>` 标签自动获得属性类型检查(由 @wc-kit/core 元素类实例类型推导,无需手工维护):
19
+
20
+ ```vue
21
+ <template>
22
+ <!-- label: string;clearable: boolean —— 类型正确 ✓ -->
23
+ <wc-input :label="title" clearable @wc-change="onChange" />
24
+ <!-- 错误属性会在 vue-tsc 下报错 ✗ -->
25
+ </template>
26
+
27
+ <script setup lang="ts">
28
+ // 全局类型生效需要 tsconfig include 覆盖到本包的类型声明,
29
+ // 或在 env.d.ts 中显式引用:
30
+ import type {} from '@wc-kit/vue/global-components';
31
+ </script>
32
+ ```
33
+
34
+ ## v-model 适配说明
35
+
36
+ Vue 对**自定义元素**的 `v-model` 会绑定 `value` 属性 + 监听原生 `input` 事件,
37
+ 而 `wc-input` 等组件派发的是 **`wc-input` / `wc-change`** 自定义事件(`detail.value` 携带值),
38
+ 因此原生 `v-model` 不生效。推荐写法:
39
+
40
+ ```vue
41
+ <template>
42
+ <!-- 方式一:value 属性 + wc-input 事件(输入过程实时同步) -->
43
+ <wc-input :value="text" @wc-input="text = $event.detail.value" />
44
+
45
+ <!-- 方式二:失焦/回车才提交时用 wc-change -->
46
+ <wc-input :value="text" @wc-change="text = $event.detail.value" />
47
+ </template>
48
+ ```
49
+
50
+ 各组件的值事件:`wc-input` / `wc-textarea` / `wc-slider` / `wc-input-number`(`wc-input` 拖动 + `wc-change` 提交)、
51
+ `wc-select` / `wc-checkbox` / `wc-radio` / `wc-switch` / `wc-date-picker` / `wc-tabs` / `wc-pagination`(`wc-change`)。
52
+
53
+ > 如需真正的 `v-model` 语法糖,可在项目中封装一层 `defineModel` + 事件转发的薄包装组件,或等待后续版本提供官方指令。