Laravel:从Blade更改为JS前端框架 [英] Laravel: changing from Blade to JS frontend framework

查看:399
本文介绍了Laravel:从Blade更改为JS前端框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Laravel应用程序,它使用Blade作为前端.我感觉更好的选择(更多面向未来的选择)是切换到Angular,Vue或React,(尚不确定我将使用哪一个,但这不是本文的问题)

I have a Laravel application which is using Blade as the frontend. I'm feeling the better (more future proof) option would be to switch to Angular, Vue or React, (not entirely sure yet which one I will use but that's not the question of this post)

我一直认为后端代码应公开API,以使这些JS前端框架能够正常工作.我目前不公开任何API.

I've always thought that the backend code should expose an API in order for these JS frontend frameworks to work. I currently don't expose any sort of API.

我基本上是通过正常方式设计的:

I basically designed it in the normal way:

  1. 定义指向控制器的路由
  2. 创建控制器功能并将其定向到视图
  3. 创建Blade视图

问题对:

  1. 我应该重新设计后端以公开这样的API吗?
  2. 我可以从控制器中调用Angular/Vue/React代码吗,类似于我的代码 用刀片做什么?
  3. 如果问题1的答案为是, 那我不应该考虑改用流明吗?
  1. Should I redesign my backend to expose such an API?
  2. Can I call Angular/Vue/React code from my controllers, similar to what I'm doing with Blade?
  3. In case the answer is yes to question 1, shouldn't I consider changing to Lumen then?

推荐答案

使用前端框架意味着您最有可能将后端构建为API, 常见的情况是:

using frontend framework means you would most likely build you backend as an API, a common scenario is:

  1. 将路线单点路由到加载角度/vue应用的控制器
  2. angular/vue应用程序将处理视图和模板.
  3. 一旦加载了应用程序,您只需要通过公开的api与服务器进行通信

您无法从laravel控制器调用js代码,并且可能不需要.

you can't call you js code from laravel controller and you probably won't need to.

关于您的问题lumen vs laravel,我认为这取决于您.两者都有专业的缺点.

as for your question lumen vs laravel, I think it's up to you to decide that. both have pro's con's.

这篇关于Laravel:从Blade更改为JS前端框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆