search
HomeBackend DevelopmentPHP Tutorial关于在服务器端用vuejs,并希望能在服务器端把页面渲染出来的若干问题,谢谢

首页,我想我寻求的这个应该是个临界于依赖php模板渲染页面和SPA之间的一个过渡的方案吧,我打算把这一步步的变化都测试下;
也是继 http://segmentfault.com/q/1010000004067025 这个问题进一步的思考;

1.模块化 or 单文件组件化 ?

  • 在服务器端渲染的页面,用上vue的模块化或.vue单文件组件化来处理数据,输出的是完整的Html吗?还是说会传到客户端去渲染?

  • 主要是对于.vue的组件化的,把php出来的数据交给window(无法直接嵌入php数据),绑给vue,这会是在服务器端渲染吗?

  • 模块化还是可以直接嵌入php数据的话,那应该还是会输出html来吧?

  • 如果交给node层来渲染是不是直接就出了html?

2.前端vue与模板的关联方法:多blade模板 or 单个blade模板(PHP框架laravel自带模板引擎)?

  • 使用多个Blade模板渲染,但都包含同一个入口,然后每次去调用不同的组件来使用,是否会把多余的组件一同打包进来?是不是有更好地方法?

  • 使用单Blade模板渲染,对应多个入口,根据每次的不同参数引入不同入口从而来渲染页面,是否可行?

1和2的问题将配合进行,并且里面可交叉,那哪一种是更好的方案呢?

谢谢!可能说的有点乱,想试试这种过渡方案的具体实现方案。

回复内容:

首页,我想我寻求的这个应该是个临界于依赖php模板渲染页面和SPA之间的一个过渡的方案吧,我打算把这一步步的变化都测试下;
也是继 http://segmentfault.com/q/1010000004067025 这个问题进一步的思考;

1.模块化 or 单文件组件化 ?

  • 在服务器端渲染的页面,用上vue的模块化或.vue单文件组件化来处理数据,输出的是完整的Html吗?还是说会传到客户端去渲染?

  • 主要是对于.vue的组件化的,把php出来的数据交给window(无法直接嵌入php数据),绑给vue,这会是在服务器端渲染吗?

  • 模块化还是可以直接嵌入php数据的话,那应该还是会输出html来吧?

  • 如果交给node层来渲染是不是直接就出了html?

2.前端vue与模板的关联方法:多blade模板 or 单个blade模板(PHP框架laravel自带模板引擎)?

  • 使用多个Blade模板渲染,但都包含同一个入口,然后每次去调用不同的组件来使用,是否会把多余的组件一同打包进来?是不是有更好地方法?

  • 使用单Blade模板渲染,对应多个入口,根据每次的不同参数引入不同入口从而来渲染页面,是否可行?

1和2的问题将配合进行,并且里面可交叉,那哪一种是更好的方案呢?

谢谢!可能说的有点乱,想试试这种过渡方案的具体实现方案。

首先,vue 是客户端的,
如果要在服务端渲染 vue 的话,
也不是不行,得经过 nodejs 来弄,
现在还没有官方推荐的成熟方案。

laravel + vue 本质上是:
laravel 通过 blade 引擎渲染出 html,
返回给客户端执行 vue 的相应脚本。

解决的是 vue 本身没有或不大方便的 路由和权限验证

使用node+vue.js实现SPA应用,解决了SPA应用的最大缺点SEO 之前写的文章 现在在完善项目中。

.vue 文件 在服务器上没法加载 所以放弃使用了,
服务端渲染 可以用第3方写的vue-server插件

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
Optimize PHP Code: Reducing Memory Usage & Execution TimeOptimize PHP Code: Reducing Memory Usage & Execution TimeMay 10, 2025 am 12:04 AM

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

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

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool