前端跟後端的MVC架構有什麼不同?
最好能分別給出M,V,C分別指的什麼。
題主之前是做PHP後端的,看前端的MVC非常不理解……謝謝。
前端開發的MVC架構核心是事件流;後端開發的核心是數據流。
回答後半個問題。前相對而言,後端的特點,能訪問資料庫,頁面是整個刷新掉的。而前端的特點,只能緩存伺服器給的數據,界面需要局部更新來保證用戶體驗。
這兩個差別導致 Model 跟 View 的關係大相徑庭。一個結果就是前端數據界面的綁定相對嚴重。
傳統MVC:
Interactions[edit]
In addition to dividing the application into three kinds of components, the model–view–controller design defines the interactions between them.
[7]
- A controller can send commands to the model to update the model"s state (e.g., editing a document). It can also send commands to its associated view to change the view"s presentation of the model (e.g., by scrolling through a document).
- A model stores data that is retrieved by the controller and displayed in the view. Whenever there is a change to the data it is updated by the controller.
- A view requests information from the model that it uses to generate an output representation to the user.
前端MVC大部分都是MVVM:
Components of the MVVM pattern[edit]ModelModel refers either to a domain model, which represents the real state content (an object-oriented approach), or to the data access layer that represents that content (a data-centric approach).
[citation needed]
ViewAs in the MVC and MVP patterns, the view is the user interface (UI).
[further explanation needed]
View modelThe view model is an abstraction of the view that exposes public properties and commands. Instead of the controller of the MVC pattern, or the presenter of the MVP pattern, MVVM has a binder. In the view model, this binder mediates communication between the view and the data binder.
[clarification needed]
The view model has been described as a state of the data in the model.
[6]
BinderDeclarative data- and command-binding are implicit in the MVVM pattern. In the Microsoft solution stack, the binder is a markup language called XAML.
[7]
The binder frees the developer from being obliged to write boiler-plate logic to synchronise the view model and view. When implemented outside of the Microsoft stack the presence of a declarative databinding technology is a key enabler of the pattern.
[4]
[8]
[clarification needed]
view就是HTML;model就是js寫的class,一般是以伺服器端返回的JSON為主;viewmodel就是view的數據展現形式,裡面有各種屬性和方法可以與view進行綁定;binder就是各種MVC框架,在綁定後,你根據它們的規範實現的viewmodel就可以與view自動的進行互動,例如viewmodel里的屬性的值發生變化的時候view上綁定對應屬性的html也會自動更新。
前端mvvm,後端mvc。多個v呢。先留坑,等有空詳答。
不去谷歌問問MVC和MVVM的區別么?估計更有感觸
後端MVC中的view是前端MCV的全部 :
主要是C 這一塊
後端的C一般就是URL和Http Method
而前端既有URL (hashtag /push state) 也有DOM event 都會對View造成影響 所以前端經常稱自己為MV**框架 就是這個原因推薦閱讀:
※到底是前端根據後端來寫還是後端根據前端來寫呢?
※前後端分離端nodejs mongodb express後台spring restfui webservice,mybatis mysql這樣適合中大型應用嗎?
※超小團隊選擇django還是flask?
※就想看技術書籍,但是動手編程慾望不大怎麼辦?
TAG:前端開發 | JavaScript | 後端技術 | MVC |