[英]Passing data to React component through Laravel blade
I don't know if this is even possible or maybe this is just a stupid question, but here it goes:我不知道这是否可能,或者这只是一个愚蠢的问题,但它是这样的:
Is it possible to pass data from you Laravel controller to a React Component through a blade template?是否可以通过刀片模板将数据从 Laravel 控制器传递到 React 组件?
I'm asking this because I have a form where I have three static form elements ( name
, description
& deadline
) that are defined in blade and a dynamic part that adds elements (extra fields; name
, description
and type
for each extra field
) to the form on a button click.我之所以这么问是因为我有一个表单,其中包含在 Blade 中定义的三个静态表单元素(
name
、 description
和deadline
)和一个添加元素的动态部分(额外字段;每个额外field
name
、 description
和type
)单击按钮转到表单。
I also want to use the component for editing, so I need to push data into it.我也想使用组件进行编辑,所以我需要将数据推入其中。 My train of thought was to use React for the dynamic part so that I don't have to use native JS or jQuery to build this.
我的思路是将 React 用于动态部分,这样我就不必使用原生 JS 或 jQuery 来构建它。
Note that I'm a beginner at React so I this point I don't even know if I'm doing it right/wrong.请注意,我是 React 的初学者,所以在这一点上我什至不知道我做得对还是错。 I've added a screenshot of the form to show illustrate what I mean.
我添加了表格的屏幕截图来说明我的意思。 (sorry it's in Dutch but I've tried to add some notes to make it clear)
(对不起,它是荷兰语,但我试图添加一些注释以使其清楚)
This maybe will help you out:这可能会帮助你:
under Rendering json ..在渲染 json 下..
This is how vuejs
works.这就是
vuejs
工作原理。 Your controller would return a variable like $project
and you would pass it as a prop into your component by using @json($project)
您的控制器将返回一个像
$project
这样的变量,您可以使用@json($project)
将它作为道具传递给您的组件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.