We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2020-12-18
通过对逻辑层的封装,让原生小程序使用 Vue3 的 Composotion API
index.wxml
<view> <view>{{count}}</view> <button bindtap="add">数字 +1</button> </view>
index.js
import { Epage, ref, onShowHooks } from "enhance-weapp" function useCount() { const count = ref(0) const add = () => { count.value++ } onShowHooks(() => { console.log("我是useCount") }) return { count, add, } } Epage({ setup() { onShowHooks(() => { console.log("我是setup") }) return useCount() }, })
流程图先走一波
options
setup
setupData
options.data
reactive
this.data$
this.data
this.setData(this.data)
this.__oldData__
watch
this.setData(diffData)
以上是核心的实现思路,除此之外还有全局 mixins、生命周期阻塞执行、全局生命周期控制等逻辑,具体可以去 enhance-weapp,看下介绍和源码。
mixins
如果本篇内容对你有帮助,欢迎点赞 star👍。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
2020-12-18
使用示例
index.wxml
index.js
原理简述
流程图先走一波
options
对象属性进行遍历,对所有的生命周期方法进行装饰,将生命周期改造成数组结构,并提供相关的 hooks 方式以调用注册。setup
函数,拿到其返回值setupData
。options.data
对象副本(如果有的话),使用reactive
将其响应式后保存到this.data$
属性上。setupData
,将其值直接赋值给this.data$
,响应式解包赋值给this.data
。this.setData(this.data)
,同步数据至渲染层。this.data
副本至this.__oldData__
。watch
监听this.data$
,响应式触发后 diffthis.data$
与this.__oldData__
。this.setData(diffData)
,同步数据至渲染层。以上是核心的实现思路,除此之外还有全局
mixins
、生命周期阻塞执行、全局生命周期控制等逻辑,具体可以去 enhance-weapp,看下介绍和源码。如果本篇内容对你有帮助,欢迎点赞 star👍。
The text was updated successfully, but these errors were encountered: