▶_MiniApp Toolkit

wevu

工具

weapp-vite 生态的 Vue 3 风格小程序运行时,提供响应式数据系统、快照 diff + setData 优化、轻量状态管理,让原生小程序开发也能享受 Vue 3 Composition API 的开发体验

wevuweapp-vitevue3reactiveruntimesetdatadiffminiprogramwechat

详细文档

资源概述#

wevuweapp-vite 生态的 Vue 3 风格小程序运行时。它将 Vue 3 的响应式系统(基于 @vue/reactivity)引入微信原生小程序开发,让开发者能用 Composition API(ref / computed / reactive / watch)编写小程序逻辑,同时自动处理 setData 性能优化。

核心特性#

  • Vue 3 响应式 APIref() / 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

设计规范#

架构设计#

code
┌─────────────────────────────────────────────┐
│               开发者代码                      │
│   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-computedconst double = computed(() => count.value * 2)
状态管理globalData / 第三方库模块级 reactive() 直接共享
setData 优化手动 diff 或全量设置自动快照 diff,仅发送变化字段
TypeScript手动声明 IData自动类型推断
生命周期onLoad/onUnload 分散watchEffect 自动追踪/清理

审核规范#

不适用(工具库,非平台类资源)

开发指南#

快速开始#

code
# 创建 Wevu 项目(推荐方式)
npm create weapp-vite@latest -- --template wevu

# 或手动安装
npm install wevu

响应式数据#

code
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)#

code
<!-- 支持 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>

跨页面状态共享#

code
// 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)#

code
// 在 app.js 入口引入,自动注册 polyfill
import '@wevu/web-apis/install';

// 现在可以在小程序中使用标准 Web API
fetch('/api/data').then(r => r.json());
localStorage.setItem('key', 'value');

常见陷阱#

  1. ref vs reactiveref() 用于基本类型,需 .value 访问;reactive() 用于对象,直接访问属性。模板中 ref 自动解包无需 .value
  2. setData 性能:Wevu 的 diff 策略在组件层级做快照对比,深层嵌套对象(>5 层)可能影响 diff 性能,建议扁平化数据结构
  3. 生命周期限制watchEffect 自动在页面 onUnload 时清理副作用,但 setInterval 等需手动清理
  4. 兼容性:Wevu 目前仅支持微信小程序,支付宝/百度等平台支持在路线图中

生态资源#

weapp-vite 工具链全景#

工具npm 包功能说明
weapp-viteweapp-vite构建工具Vite 驱动的小程序打包器
Wevuwevu响应式运行时Vue 3 风格小程序开发 ← 本条目
Wevu Web APIs@wevu/web-apisAPI Polyfillfetch / localStorage 等
Wevu Compiler@wevu/compiler模板编译器Vue 模板 → WXML
Weapp IDE CLIweapp-ide-cliCLI 工具开发者工具命令行增强
Volar 插件@weapp-vite/volarIDE 支持IntelliSense / 类型检查

对比方案#

方案Stars模式响应式setData 优化
Wevu450⭐Vue 3 原生风格✅ @vue/reactivity✅ 快照 diff
Westore4287⭐JSON diff自研✅ JSON diff
mini-stores179⭐状态管理多 Store✅ JSON diff
MobX bindings250⭐MobX✅ MobX observable❌ 手动
原生 setData-命令式❌ 全量设置

版本更新#

  • v6.19.4(2026-08-08):新增 useStorage 组合式函数,响应式封装 wx.getStorageSync
  • v6.15.0(2026-07):@wevu/web-apis 新增 IntersectionObserver polyfill
  • 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