[英]Why can i not get the Data from my laravel database with vue.js?
我有以下問題:我有一個完整設置 laravel 上的一些公司名稱的表格,我希望它們通過 vue.js 顯示我通過教程完成了以下操作,但它不會按預期工作。 我剛拿到表 Header。 它必須通過 API 解決。
請幫忙:)
歡迎.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
<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>
固件.vue
<template>
<td>{firmas.id}</td>
<td>{firmas.firmenname}</td>
</template>
<script>
export default {
name: "firmas",
props: {
firmas: {
type: Object
}
}
}
</script>
路線/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');
你叫錯了路線
嘗試這個:
return{ url: "http://localhost:5174/api/firma", firmas: [] }; },
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.