laravel - 从 laravel Blade 到 vue 组件传递路由导致重复输出

标签 laravel vue.js

我将 6 条路由从 Blade 文件传递​​到 Vue 组件,但是当我执行并输出路由时,这 6 条路由以 6 组为一组出现 6 次。每组相同的 6 条路由在vue 开发工具。

index.blade.php(一些循环是在blade中完成的)

 @foreach (App\Questions::all() as $question)
    <question
        :questions="{{App\Questions::all()}}"
        :user="{{$user}}"     
        routes="{{route($question->route)}}">  //Passing the 6 question routes
    </question>
 @endforeach

问题.vue

 <div v-for="question in questions">
    <div v-for="route in routes">
          <a :href="route">
            {{ question.title }}
          </a>
     </div>
 </div>


<script>
export default {
    props: ["questions", "user", "routes"];
}
</script>

为什么它们显示为 6 个不同的组件,每个组件具有 6 次相同的信息。

谢谢。

最佳答案

循环六次,在此处创建六个组件:

 @foreach (App\Questions::all() as $question)

您可以通过获取所有问题模型将相同的问题绑定(bind)到每个组件。

:questions="{{App\Questions::all()}}"

尝试绑定(bind)到:

 :questions="{{ $question }}"

关于laravel - 从 laravel Blade 到 vue 组件传递路由导致重复输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63819147/

相关文章:

javascript - vue w/axios 应该使用从另一个 get-request 检索的变量进行 get-request

php - 如何从 View 中在 Controller 中传递 id(在 laravel 中编辑用户)

javascript - 我可以向 Google Charts Load 的回调函数传递参数吗?

javascript - 在引导模式的不同选项卡上显示 laravel 身份验证错误

laravel - 更新 laravel 6 -> 8 时 Composer 更新错误

php - 在 Laravel 5.0 中限制路由的最佳方法是什么?

javascript - vue Js从对象绑定(bind)到数组

javascript - Vue,Observable 上的过滤器属性

vue.js - cy.clear() 未正确清除输入字段 - Cypress

javascript - 我如何在 vue js 中使用内联声明的变量?