【问题标题】:Passing route from laravel blade to vue component causing duplicate output从 laravel 刀片传递路由到 vue 组件导致重复输出
【发布时间】:2020-12-28 07:54:18
【问题描述】:

我将 6 条路由从刀片文件传递到 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 次相同的信息。

谢谢。

【问题讨论】:

    标签: laravel vue.js


    【解决方案1】:

    你循环六次,在这里创建六个组件:

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

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

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

    尝试绑定到:

     :questions="{{ $question }}"
    

    【讨论】:

    • 那么我是否只需要绑定到 ``` :questions="{{ $question }}"`` 就可以删除 userroutes 绑定?
    • 这实际上是正确的答案,我不必在我的 vue 组件中使用v-for,因为我已经在刀片文件中循环了。我也确实通过了$question 以及routesuser 作为绑定属性。谢谢@Bennett
    猜你喜欢
    • 2017-02-24
    • 2021-10-22
    • 2018-08-24
    • 2021-01-21
    • 1970-01-01
    • 2018-06-20
    • 2021-07-05
    • 2018-10-13
    • 2017-07-27
    相关资源
    最近更新 更多