
wevu
工具weapp-vite 生态的 Vue 3 风格小程序运行时,提供响应式数据系统、快照 diff + setData 优化、轻量状态管理,让原生小程序开发也能享受 Vue 3 Composition API 的开发体验
wevuweapp-vitevue3reactiveruntimesetdatadiffminiprogramwechat
详细文档
资源概述#
wevu 是 weapp-vite 生态的 Vue 3 风格小程序运行时。它将 Vue 3 的响应式系统(基于 @vue/reactivity)引入微信原生小程序开发,让开发者能用 Composition API(ref / computed / reactive / watch)编写小程序逻辑,同时自动处理 setData 性能优化。
核心特性#
- Vue 3 响应式 API:
ref()/reactive()/computed()/watch()/watchEffect()完整支持 - 自动 setData 优化:快照 diff 策略,仅发送变化的数据到视图层,减少通信开销
- 轻量状态管理:跨页面/组件共享响应式状态,无需额外状态管理库
- 模板编译器:
@wevu/compiler支持 Vue 风格模板语法(v-if/v-for/{{ }})编译为原生 WXML - Web API Polyfill:
@wevu/web-apis提供浏览器标准 API(fetch / localStorage / IntersectionObserver 等) - TypeScript 原生:完全类型安全,IDE 智能提示
项目数据#
| 指标 | 数值 |
|---|---|
| GitHub Stars(weapp-vite org) | 450⭐ |
| npm 版本数 | 171(latest: 6.19.4) |
| npm 最后发布 | 2026-08-08 |
| 月下载量 | ~7,137 |
| 许可证 | MIT |
| 创建年份 | 2024 |
| 关联构建工具 | weapp-vite |
设计规范#
架构设计#
┌─────────────────────────────────────────────┐
│ 开发者代码 │
│ ref() / reactive() / computed() / watch() │
└──────────────┬──────────────────────────────┘
│ @vue/reactivity 依赖追踪
┌──────────────┴──────────────────────────────┐
│ wevu 运行时 │
│ ┌─────────────┐ ┌──────────────────────┐ │
│ │ 响应式系统 │ │ 快照 diff 引擎 │ │
│ │ (reactivity) │ │ (snapshot → setData) │ │
│ └─────────────┘ └──────────────────────┘ │
│ ┌─────────────┐ ┌──────────────────────┐ │
│ │ 生命周期桥接 │ │ 事件系统 │ │
│ │ (onLoad → │ │ (bind:tap → handler) │ │
│ │ onUnmount) │ │ │ │
│ └─────────────┘ └──────────────────────┘ │
└──────────────┬──────────────────────────────┘
│ 最小化 setData 调用
┌──────────────┴──────────────────────────────┐
│ 微信小程序原生层 │
│ Page() / Component() / setData() │
└─────────────────────────────────────────────┘
与原生小程序开发对比#
| 维度 | 原生小程序 | Wevu 模式 |
|---|---|---|
| 数据绑定 | this.setData({ count: 1 }) | const count = ref(0); count.value = 1 |
| 计算属性 | 手动实现或用 miniprogram-computed | const double = computed(() => count.value * 2) |
| 状态管理 | globalData / 第三方库 | 模块级 reactive() 直接共享 |
| setData 优化 | 手动 diff 或全量设置 | 自动快照 diff,仅发送变化字段 |
| TypeScript | 手动声明 IData | 自动类型推断 |
| 生命周期 | onLoad/onUnload 分散 | watchEffect 自动追踪/清理 |
审核规范#
不适用(工具库,非平台类资源)
开发指南#
快速开始#
# 创建 Wevu 项目(推荐方式)
npm create weapp-vite@latest -- --template wevu
# 或手动安装
npm install wevu
响应式数据#
import { ref, reactive, computed } from 'wevu';
// 页面中使用
Page({
setup() {
// 响应式基本类型
const count = ref(0);
// 响应式对象
const user = reactive({
name: '张三',
age: 25
});
// 计算属性(自动依赖追踪)
const doubleCount = computed(() => count.value * 2);
// 修改数据 → 自动触发 setData(仅 diff 变化部分)
const increment = () => {
count.value++;
};
return { count, user, doubleCount, increment };
}
});
模板语法(@wevu/compiler)#
<!-- 支持 Vue 风格指令 -->
<view class="container">
<text>{{ count }}</text>
<text>Double: {{ doubleCount }}</text>
<button bind:tap="increment">+1</button>
<!-- v-if 条件渲染 -->
<view v-if="count > 10">Count is large!</view>
<!-- v-for 列表渲染 -->
<view v-for="item in list" :key="item.id">
{{ item.name }}
</view>
</view>
跨页面状态共享#
// store/user.ts — 模块级响应式状态
import { reactive, computed } from 'wevu';
export const userStore = reactive({
token: '',
userInfo: null as UserInfo | null,
});
export const isLoggedIn = computed(() => !!userStore.token);
export function login(token: string, info: UserInfo) {
userStore.token = token;
userStore.userInfo = info;
}
// 页面 A
Page({
setup() {
return { isLoggedIn, userStore };
}
});
// 页面 B — 自动同步响应
Page({
setup() {
return { isLoggedIn };
}
});
Web API Polyfill(@wevu/web-apis)#
// 在 app.js 入口引入,自动注册 polyfill
import '@wevu/web-apis/install';
// 现在可以在小程序中使用标准 Web API
fetch('/api/data').then(r => r.json());
localStorage.setItem('key', 'value');
常见陷阱#
- ref vs reactive:
ref()用于基本类型,需.value访问;reactive()用于对象,直接访问属性。模板中 ref 自动解包无需.value - setData 性能:Wevu 的 diff 策略在组件层级做快照对比,深层嵌套对象(>5 层)可能影响 diff 性能,建议扁平化数据结构
- 生命周期限制:
watchEffect自动在页面onUnload时清理副作用,但setInterval等需手动清理 - 兼容性:Wevu 目前仅支持微信小程序,支付宝/百度等平台支持在路线图中
生态资源#
weapp-vite 工具链全景#
| 工具 | npm 包 | 功能 | 说明 |
|---|---|---|---|
| weapp-vite | weapp-vite | 构建工具 | Vite 驱动的小程序打包器 |
| Wevu | wevu | 响应式运行时 | Vue 3 风格小程序开发 ← 本条目 |
| Wevu Web APIs | @wevu/web-apis | API Polyfill | fetch / localStorage 等 |
| Wevu Compiler | @wevu/compiler | 模板编译器 | Vue 模板 → WXML |
| Weapp IDE CLI | weapp-ide-cli | CLI 工具 | 开发者工具命令行增强 |
| Volar 插件 | @weapp-vite/volar | IDE 支持 | IntelliSense / 类型检查 |
对比方案#
| 方案 | Stars | 模式 | 响应式 | setData 优化 |
|---|---|---|---|---|
| Wevu | 450⭐ | Vue 3 原生风格 | ✅ @vue/reactivity | ✅ 快照 diff |
| Westore | 4287⭐ | JSON diff | 自研 | ✅ JSON diff |
| mini-stores | 179⭐ | 状态管理 | 多 Store | ✅ JSON diff |
| MobX bindings | 250⭐ | MobX | ✅ MobX observable | ❌ 手动 |
| 原生 setData | - | 命令式 | ❌ | ❌ 全量设置 |
版本更新#
- v6.19.4(2026-08-08):新增
useStorage组合式函数,响应式封装wx.getStorageSync - v6.15.0(2026-07):
@wevu/web-apis新增IntersectionObserverpolyfill - v6.10.0(2026-06):模板编译器支持
v-show指令 - v6.0.0(2026-04):重大更新,完全重写响应式系统底层,对齐 Vue 3.4 reactivity
- v5.0.0(2026-01):与 weapp-vite 5.0 对齐,支持 ESM-only