我实际上正在努力将数据传递到GET请求页面,我试图将数据库中的数据传递给Dashboard.vue组件(使用Laravel 8 + Inertia.js堆栈)
但是什么都没有发生,为什么呢?
控制器组件:
public function index(Request $request)
{
return Inertia::render('Dashboard', [
'percentages' => $percentages = DB::table('profits')->where('user_id', $request->user()->id)->sum('percentage'),
'profits' => $profits = DB::table('profits')->where('user_id', $request->user()->id)->sum('total_profit'),
]);
}
前端:
<div class="container">
<div class="row">
<div class="col-sm-5 text-center fund-profits">
{{profits}}
</div>
<div class="col-sm-2 text-center nomad-separator">
|
</div>
<div class="col-sm-5 text-center fund-profits">
{{percentages}}
</div>
</div>
</div>
<script>
import JetApplicationLogo from './../Jetstream/ApplicationLogo'
export default {
props: ['percentages', 'profits'],
components: {
JetApplicationLogo,
},
}
</script>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我昨天遇到了类似的问题。 我在
routes/web.php中再次渲染时使用了inertia,我认为发生了覆盖。尝试在你的路由中不使用inertia,对我有用。