博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
三分钟让你了解MVC和MVVM模式
阅读量:4149 次
发布时间:2019-05-25

本文共 666 字,大约阅读时间需要 2 分钟。

1.MVC关注的是Model的不变,所以,在MVC模型里,Model不依赖于View,但是 View是依赖于Model的。不仅如此,因为有一些业务逻辑在View里实现了,导致要更改View也是比较困难的,至少那些业务逻辑是无法重用的。

2.MVVM是一种更好的UI模式解决方案,MVVM通过数据双向绑定让数据自动地双向同步。

MVC设计模式

View(视图层)       Model(模型)     Controller(控制器)

  • View 传送指令到 Controller
  • Model 将新的数据发送到 View,用户得到反馈
  • Controller 完成业务逻辑后,要求 Model 改变状态

用户与View进行交互,Controller进行业务逻辑处理,控制器从模型中请求数据,并反馈给视图层,视图将数据呈现给用户。

MVVM设计模式

Model(模型)    View(视图)  View Model(视图模型)

  • V    HTML元素
  • VM    View-Model
  • M     模型数据(json->{},[] )

MVVM与MVC最大的区别:MVVM实现了View和Model的自动同步,也就是当Model的属性改值变时,我们不用再自己手动操作Dom元素,来改变View的显示,而是改变属性后该属性对应View层显示会自动改变。

MVVM代表框架:Angularjs、React、Vue。

MVVM主要解决了MVC中大量 DOM元素操作,使得页面渲染性能降低,加载速度变慢,影响用户体验。

 

--------------如果大家喜欢我的博客,可以点击左上角的关注哦。

转载地址:http://iupti.baihongyu.com/

你可能感兴趣的文章
[LeetCode]Two Sum
查看>>
[LeetCode]Unique Binary Search Trees
查看>>
[LeetCode]Unique Binary Search Trees II
查看>>
[LeetCode]Unique Paths
查看>>
[LeetCode]Unique Paths II
查看>>
[LeetCode]Valid Number
查看>>
[LeetCode]Valid Palindrome
查看>>
[LeetCode]Valid Parentheses
查看>>
[LeetCode]Valid Sudoku
查看>>
[LeetCode]Validate Binary Search Tree
查看>>
[LeetCode]Wildcard Matching
查看>>
[LeetCode]Word Ladder
查看>>
[LeetCode]Word Ladder II
查看>>
[LeetCode]Word Search
查看>>
[LeetCode]ZigZag Conversion
查看>>
Divide and Conquer
查看>>
Greedy
查看>>
Dynamic Programming
查看>>
Sorting
查看>>
Bit manipulation
查看>>