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

对MVVM的理解 #16

Open
Pieces312 opened this issue Sep 29, 2020 · 0 comments
Open

对MVVM的理解 #16

Pieces312 opened this issue Sep 29, 2020 · 0 comments
Labels

Comments

@Pieces312
Copy link
Owner

M:Model(模型) V:View(视图) VM:ViewModel(视图模型)

在MVVM框架中是不允许模型和视图直接通信的,只能通过ViewModel进行交互。VM能监听到数据的变化并通知视图进行自动更新;而当用户操作视图时,VM也能监听到视图的改动,然后通知数据做出相应的改动。这实际上就实现了双向绑定。

其中,MVVM中的核心就是VM,是暴露公共属性和命令的视图的抽象。它的好处是解放了程序员,前端程序员不用操作DOM,只需要关心前端的业务逻辑即可。

MVVVM 的优点:

  • 低耦合。View可以独立于Model的变化和修改,一个ViewModel可以绑定到多个不同的View上。当View变化时Model不变,Model改变时View可以不变;
  • 可重用性。把一些视图逻辑放在一个ViewModel里面,让多个View重用这段逻辑;
  • 独立开发。开发人员只用专注于业务逻辑和数据处理;

文章链接:https://juejin.im/post/6870870526341054478#heading-0

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

No branches or pull requests

1 participant