一、常用语法上的不同
1.data
image.png2.所有的内容包在setup里面,在template使用的数据和方法需要return
image.png二、使用组合式api的好处
1.按功能划分,便于维护
按照原来的写法,实现一个功能,我要写在不同的生命周期里面,不聚合~
imageOptions API
image.pngComposition API
image.png项目上的例子
image.png image.png image.png image.png2.逻辑复用
image.png image三、如何封装一个逻辑函数
其实逻辑复用函数简单理解就是 有状态的函数
比函数多了状态,比组件少了视图。
image.png image.pnggetCertificateList
image.pnguseSearch
image.png image.pnguseBoolean
image.png image.png image.png image.pnguseAsync
image.png image.png库函数
1.https://github.com/vueuse/vueuse
2.https://github.com/pikax/vue-composable
3.https://github.com/dewfall123/ahooks-vue
友情链接:
1.react hooks
助力拥抱react hooks:https://zhuanlan.zhihu.com/p/103150605?utm_source=wechat_session
react hooks函数库:https://github.com/alibaba/hooks
2.composition-api
作者分享:https://github.com/Bin-FE/binfe-salon-ppt
github:https://github.com/vuejs/composition-api
官网文档:https://v3.cn.vuejs.org/guide/composition-api-introduction.html
网友评论