【问题标题】:I'm using Laravel + vue to pass variables to vue through Blade but it doesn't display我正在使用 Laravel + vue 通过 Blade 将变量传递给 vue 但它不显示
【发布时间】:2021-04-19 01:14:59
【问题描述】:

刀片文件(JSON):

@extends('layouts.app')
    
@section('content')
    <div>
        <test-component :items='{{ $items }}'></test-component>
    </div>
@endsection

vue 组件:

<template> 
    
    <ul id="example-1">
        <li v-for="item in items" :key="item.id">
            {{ item.id }}
          </li>
    </ul>
</template>

<script>
    // Vue.js のインスタンス
    module.exports = new Vue({
        props: {
            items: {
                type: Object,
                defalut: {},
            },
        },
    })
</script>

谷歌开发者工具:

 <ul id="example-1" items="[object Object],[object Object],[object
 Object],[object Object],</ul>

警告:

[Vue 警告]:实例上未定义属性或方法“items” 但在渲染期间引用。确保该属性是 反应式,无论是在数据选项中,还是对于基于类的组件,通过 初始化属性。

处理结果会是这样。我不知道我犯了什么错误。

【问题讨论】:

  • 你能解释一下吗?
        控制器中的 $items 是什么?
    • 返回视图('chat.vue')->with('item', $items);刀片 ​​omponent>

标签: laravel vue.js laravel-blade


【解决方案1】:

只需如下定义您的道具。你为什么要像上面那样定义道具? props:['items']

【讨论】:

    【解决方案2】:
    module.exports = new Vue({
    

    这里的符号是错误的

    【讨论】:

      猜你喜欢
      • 2021-06-29
      • 2020-02-11
      • 1970-01-01
      • 2022-01-13
      • 2020-04-05
      • 2021-04-21
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多