search
HomeBackend DevelopmentPHP Tutorialjavascript - 请教一下关于前后端分离的一些疑问

今天早上看了一篇关于vue前台框架的使用教程,然后引发了我一些的疑问,望各位大神能告知一二.问题如下:

  1. 前后端分离指的是视图文件不再存在服务器脚本语言吗?意义是什么?

  2. 类似vue框架的v-for遍历数据和thinkphp的标签volist遍历有什么却别吗?是和一个在客户端运行,一个在服务端运行有关吗?还是说对页面的渲染起到不一样的作用?

  3. 前台框架和js模板引擎有什么区别?例如artTemplate模板引擎和vue框架

回复内容:

今天早上看了一篇关于vue前台框架的使用教程,然后引发了我一些的疑问,望各位大神能告知一二.问题如下:

  1. 前后端分离指的是视图文件不再存在服务器脚本语言吗?意义是什么?

  2. 类似vue框架的v-for遍历数据和thinkphp的标签volist遍历有什么却别吗?是和一个在客户端运行,一个在服务端运行有关吗?还是说对页面的渲染起到不一样的作用?

  3. 前台框架和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 等后端语言获取到数据,渲染到静态页面,并把渲染后的页面返回到客户端.

javascript - 请教一下关于前后端分离的一些疑问

分离后
客户端直接请求服务端获取静态页面,略过php/java后端获取数据步骤.
页面展示后, 通过 ajax 请求服务端接口,获取数据.并把数据渲染到页面.
接口只返回数据,因此不仅可以给 web 前端提供数据,还可以为安卓, ios 客户端提供数据,提高了接口的可用性.

javascript - 请教一下关于前后端分离的一些疑问

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment