简体   繁体   English

为什么我无法使用 vue.js 从我的 laravel 数据库中获取数据?

[英]Why can i not get the Data from my laravel database with vue.js?

I have the following Problem: I have a table with the names of some companies on a full set up laravel and i want them to be displayed via vue.js i got the following done with a tutorial but it wont work out as it's intended to.我有以下问题:我有一个完整设置 laravel 上的一些公司名称的表格,我希望它们通过 vue.js 显示我通过教程完成了以下操作,但它不会按预期工作。 I just get the Table Header.我刚拿到表 Header。 It has to be solved via the API.它必须通过 API 解决。

Please help:)请帮忙:)

Welcome.vue欢迎.vue

<script setup>
import { Head, Link } from '@inertiajs/inertia-vue3';
import axios from 'axios';

</script>

<template>
    <Head title="Welcome" />

    <div class="body">
        <FirmenListe :firmas = "firmas"></FirmenListe>
    </div>
</template>
<script>
    import FirmenListe from "./FirmenListe.vue"
    export default {
        name: "App",
        components: {
            FirmenListe
        },
        data(){
            return{
                url: "http://localhost:5174/routes/api.php",
                firmas: []
            };
        },
        methods: {
            getFirma(){
                axios.get(this.url).then(data => {
                    this.firmas = data.data;
                })
            }
        },
        created(){
            this.getFirma();
        }
    }
</script> 

FirmenListe.vue FirmenListe.vue

<template>
    <div class="firma-liste">
        <div class="data">
            <table class="ui celled table">
                <tr>
                    <th>ID</th>
                    <th>Firmenname</th>
                </tr>
                <body>
                    <tr>
                        <Firmen 
                        v-for="firmas in firmas" 
                        :key="firmas.id" 
                        :firmas="firmas"/>
                    </tr>
                </body>
            </table>
        </div>
    </div>
</template>

<script>
    import Firmen from "./Firmen.vue";
    export default {
        name: "FirmenListe",
        components: {
            Firmen
        },
        props: {
            firmas: {
                type: Array
            }
        }
    }
</script>

Firmen.vue固件.vue

<template>
    <td>{firmas.id}</td>
    <td>{firmas.firmenname}</td>
</template>

<script>
    export default {
        name: "firmas",
        props: {
            firmas: {
                type: Object
            }
        }
    }
</script>

routes/api.php路线/api.php

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FirmaController;
use App\Http\Controllers\MitarbeiterController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});
Route::resource('firma', 'FirmaController');
Route::resource('mitarbeiter', 'MitarbeiterController');

You call a wrong route你叫错了路线

try this:尝试这个:

 return{ url: "http://localhost:5174/api/firma", firmas: [] }; },

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

相关问题 我如何从Vue.js Axios返回Laravel中的数据 - How i return data in Laravel from Vue.js Axios 为什么我的页面可以获取 Vue.js 2 数据属性,但它不是响应式的? - Why my page can get the Vue.js 2 data attributes but it is not reactive? 为什么我的编辑页面在 Laravel 中不起作用? 我用过 vue.js - Why my edit page didn't work in Laravel? I used vue.js 如何在Laravel项目中设置Vue.js? - How can I set up Vue.js in my Laravel Project ? 使用 Vue.js 和 laravel/passport 和 GuzzleHttp 时无法同时获取令牌和用户数据 - Can't get token and user data at the same time while using Vue.js and laravel/passport and GuzzleHttp 无法在 Vue.js 和 Laravel 应用程序中获取 cookie 数据 - Cannot get cookie data in Vue.js and Laravel application 如何在数据更改时将数据从PHP Laravel传递到Vue.js并重新呈现Vue.js组件? - How do I pass data from PHP Laravel to Vue.js and re-render a Vue.js component when the data changes? Laravel / Vue.js-试图获取非对象的属性。 可以在Vue中访问它,但不能访问Laravel - Laravel/Vue.js - Trying to get property of non-object. Can access it in Vue but not Laravel 会话不在 Vue.js 和 Laravel 中存储数据 - Session not storing data in Vue.js & Laravel 用Laravel回响vue.js数据? - Echoing vue.js data with laravel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM