javascript - 请教一下关于前后端分离的一些疑问
今天早上看了一篇关于vue前台框架的使用教程,然后引发了我一些的疑问,望各位大神能告知一二.问题如下:
前后端分离指的是视图文件不再存在服务器脚本语言吗?意义是什么?
类似vue框架的v-for遍历数据和thinkphp的标签volist遍历有什么却别吗?是和一个在客户端运行,一个在服务端运行有关吗?还是说对页面的渲染起到不一样的作用?
前台框架和js模板引擎有什么区别?例如artTemplate模板引擎和vue框架
回复内容:
今天早上看了一篇关于vue前台框架的使用教程,然后引发了我一些的疑问,望各位大神能告知一二.问题如下:
前后端分离指的是视图文件不再存在服务器脚本语言吗?意义是什么?
类似vue框架的v-for遍历数据和thinkphp的标签volist遍历有什么却别吗?是和一个在客户端运行,一个在服务端运行有关吗?还是说对页面的渲染起到不一样的作用?
前台框架和js模板引擎有什么区别?例如artTemplate模板引擎和vue框架
非大神,以下观点纯粹个人理解,前后端分离,传统的web页面都是通过服务器生成,然后发送到浏览器渲染,js在这个过程中起辅助作用。现在,无论是vue、angular还是reactjs,操作真实的DOM也好,Virtual DOM也好,都通过js生成html,从一定程度上来说,方式和php、python的模板引擎也没有多大区别,最终都是生成html。
那前后端分离的意义在哪里?
1、对前端工程师而言,有更大的自由度(传统模式下,大概最多就算是个美工吧,现在能把自己叫做工程师了),更能专注于前端的页面的呈现、交互逻辑的处理。(ps. 一直觉得传统模式下,前端把页面做出来,后端又把他们改成模板,最后再渲染成html,这整个流程是一件很蠢的事情)
2、对于后端而言,可以脱离视图,专注于纯逻辑的处理,再也不用管你页面该怎么呈现了,想想就很开心。
3、前端和后端只用对接好api就可以了,大大减少了不必要的交流,加快开发效率。个人觉得这一点很重要。
4、当你同时要开发app、web、桌面应用的时候,api可以最大程度的被复用。
5、前端框架通过ajax的方式异步获取数据,不用为了局部的改动重新刷新整个页面,相较于服务端渲染的方案,更加流畅。
6、前后端分离后,项目更易于管理。
7、data binding, 这是服务器渲染做不到的。
etc.
2、3两个问题,其实应该差不多算是一个问题,前端框架和模板引擎以及后端模板引擎这几个的区别,如我所说,要说区别也没用多大区别,你要是了解ember.js,你看看它handlebars的写法。模板引擎算是前端框架的一部分吧,但不是全部。然后,前端框架的模板引擎和后端模板引擎,实现的方式是不一样的,后端是把模板当成文本解析之后把数据填到相应的位置,而前端框架是对真实DOM或者Virtual DOM的操作。所以后端模板引擎要改变页面,只能重新渲染,而前端框架并不用。
拿v-for和volist来说,(好吧,我并不用php),一个是遍历生成html文本,一个是在html中进行DOM操作。
前后端分离前
客户端请求服务端,通过 PHP/Java 等后端语言获取到数据,渲染到静态页面,并把渲染后的页面返回到客户端.
分离后
客户端直接请求服务端获取静态页面,略过php/java后端获取数据步骤.
页面展示后, 通过 ajax 请求服务端接口,获取数据.并把数据渲染到页面.
接口只返回数据,因此不仅可以给 web 前端提供数据,还可以为安卓, ios 客户端提供数据,提高了接口的可用性.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.
