javascript - Laravel 8 + Inertia 不渲染变量
问题描述
我实际上正在努力将数据传递到 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>
解决方案
在我的情况下,没有应用惯性的路由中间件,所以我应用了路由中间件惯性,它又开始工作了
推荐阅读
- r - 在 R 中应用自动化将数字行更改为日期
- javascript - 如何为 replaceWith() 设置事件监听器?
- python - 使用 lambda 在列表中查找最小值
- javascript - 将 javascript 循环导出到 CSV
- css - 尝试使用 CSS 隐藏 div
- java - spring,prototype和singleton有性能上的区别吗?
- r - R 包 'ps' 安装失败,因为在安装的最后一步拒绝了 mv 的权限
- twilio-functions - 如何在 Twilio Functions 中安全地存储电话号码?
- react-native - 类型错误:Method.bind 不是函数
- python - 您如何列出具有相同外键对象的所有对象?