Asking for help
What problem does this feature solve?
Composition API
VS Options API
.
Do I have to use Composition API
in every component?
I'm a PMC of Tencent TDesign. We'are going to develop a Vue3.js UI library.
But, I have a problem. https://github.com/Tencent/tdesign-vue-next/issues/58
element calendar code Is this kind of code the best code practicing ?
What does the proposed API look like?
Could you give me some advice?
Looking forword your replying.
If you could speak Chinese, it will be better for me to communicate.
Do I have to use Composition API in every component?
I don't think so, the way I think Composition API is that we can reduce duplication without using Mixin, especially for libraries.
element calendar code Is this kind of code the best code practicing ?
I don't think so, at least for now, element-plus has lots of duplicated code which is not the ultimate goal that we want, but removing duplication requires lots of iteration, right now it just cannot be done.
So my suggestion is that you should iterate your code from time to time, that's where good product came from. :)
Composition API YES!
I have refactor all components in mand-mobile-next with VCA. It's pretty cool for code organization. I think we should write less in .vue
write more in useXx.ts
And I will use Setup sugar to minimize the codes in .vue
发表一下我的看法,我认为可以无脑使用 Composition API,原因有如下几点
- 目前 TS 成为了前端项目的标配,但是 Option 语法在设计之初就没有考虑到类型系统,使用起来要有很多奇奇怪怪的 hack。但是 Composition API 是基于函数的,天生对于类型友好。如果你想使用 TS 那么 Composition API 是你的不二选择。
- 关于逻辑复用,Composition API 相对于 Mixin 的优势你们都很清楚,所以重点是当没有逻辑复用的时候是不是应该使用 Option 语法?我认为还是应该使用 Composition API 。原因是因为它给你提供了更大的自由度,你可以抽象你的代码。我的经验是,好的抽象可以将复杂的需求划分成不同的模块,然后每个模块无脑 crud,Option 语法基本上是拒绝了这方面的可行性。如果你觉得使用了 Composition API 还是会有一堆面条代码在 Setup 中,代码会很乱,但是这并不是 Composition API 的缺点,不是吗?
- 最后是关于 Composition API 灵活性的一些实例,可以参阅 Vueuse 这个库,你可以理解为带有响应式的工具函数,它带来了许多的便利,甚至可以抽象为无头组件,我们甚至可以完全将 UI 和逻辑分离,可以参阅: 这里
Closing as this is not the right place to ask questions and more than enough feedback has been provided.
Remember to use the forum or the Discord chat to ask questions!