简体   繁体   English

foreach 具有动态数据的刀片视图组件

[英]foreach a blade view component with dynamic data

i am trying to loop over blade component by passing an array data.我试图通过传递数组数据来遍历刀片组件。 it successfully compiled but it is not showing up in the browser and also not giving an error它已成功编译,但没有显示在浏览器中,也没有给出错误

here is card.blade.php file这是 card.blade.php 文件

<div>
    <h1>{{$name}}</h1>
    <h2>{{$age}}</h2>
    <h3>{{$work}}</h3>
</div>

here is main file view file这是主文件视图文件

    @php
        $arr = [
           
            ['name'=>'1','age'=>'2','work'=>'3'],
            
            ['name'=>'4','age'=>'5','work'=>'6']
        ];
    @endphp

@foreach ($arr as $de)

    <x-card :name={{$de['name']}} :age={{$de['age']}} :work={{$de['work']}}/>
    
@endforeach 

it also shows attached data when i click view source file当我单击查看源文件时,它还会显示附加数据


    <x-card :name=1 :age=2 :work=3/>
    

    <x-card :name=4 :age=5 :work=6/>

but i is not showing up in the browser, browser is blank但我没有出现在浏览器中,浏览器是空白的

You just need to delete {{}} syntax from the attributes您只需要从属性中删除{{}}语法

 <x-card :name="$de['name']" :age="$de['age']" :work="$de['work']"/>

for more info check the Component-Attributes from the docs有关更多信息,请查看文档中的Component-Attributes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM