如何使用interiajs从控制器返回数据
这是我的productController
public function index()
{
return Product::all();
}
方法
我正在寻找一种从惯性请求中返回此方法的
Route::get('/', function () {
return Inertia::render('App', [ProductController::class, 'index']);
});
这是我的vue组件(不是我试图获取数据的方式的确切方式)
<template>
</template>
<script>
props: {
index: Array,
},
</script>
This is my ProductController
public function index()
{
return Product::all();
}
I'm looking a way to return this method from an Inertia request to my Vue component, This is the way I tried this,
routes/web.php
Route::get('/', function () {
return Inertia::render('App', [ProductController::class, 'index']);
});
And here is my Vue component (Not the exact one the way I'm trying to get the data)
<template>
</template>
<script>
props: {
index: Array,
},
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的控制器中,您可以将产品列表传递给组件:
doc: https://inertiajs.com/responses
然后声明您的路线如:
这将创建
/products
路由,该路由将指向您的控制器的索引操作,该操作将将产品列表返回到您的组件。在您的组件中,您可以访问产品:
In your controller, you can pass the list of your products to your component doing:
Doc: https://inertiajs.com/responses
Then declare your route like:
This will create a
/products
route that will point to the index action of your controller that will return the list of products to your component.And in your component, you can access the products: