Skip to content
New issue

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

[vue] 你了解什么是函数式组件吗? #436

Open
haizhilin2013 opened this issue Jun 22, 2019 · 4 comments
Open

[vue] 你了解什么是函数式组件吗? #436

haizhilin2013 opened this issue Jun 22, 2019 · 4 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] 你了解什么是函数式组件吗?

@haizhilin2013 haizhilin2013 added the vue vue label Jun 22, 2019
@Kntt
Copy link

Kntt commented Jul 4, 2019

函数式组件:

需要提供一个render方法, 接受一个参数(createElement函数), 方法内根据业务逻辑,通过createElement创建vnodes,最后return vnodes

createElement函数, 三个参数, 第一个参数是html标签或自定义组件,第二个参数一个obj(包含props, on...等等), 第三个参数children(通过createElement构建, 或者字符串)

@censek
Copy link

censek commented Oct 29, 2019

@zhangkuibao
Copy link

我的理解是:将一个组件的功能抽离出来,只管理状态和数据,这样就可以应对一些功能相似但是布局不同的业务需求。
比如一个tagList组件,它的核心功能就是维护一个列表,并且可以添加和删除,把这个核心功能抽离出来作为一个函数式组件,只管理这个列表的添加、删除状态,再暴露一些其他可能用到的数据(如详情列表),然后通过二次封装来实现具体样式。
参考:函数式组件在Vue.js中的运用

@sc950828
Copy link

functional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

5 participants