php - laravel 和 vue,加载没有预期道具的视图
问题描述
我之前问过一个关于这个的问题,但我仍然被困住并且遇到了一些问题。
现在,如果我访问 site.com/status/12345,那么我将获得我所期望的状态。具有 id (12345) 的路由命中了一个控制器方法,该方法将该 id 传入并在视图中返回它的 json 版本,我将它用作道具并在页面加载时使用它调用函数。
但是,如果我只是去 site.com/status (它应该点击我的索引方法,只返回基本视图),那么我会得到“未定义的变量 entryKey”。
显然,我将控制器中的 entryKey 值添加到我的刀片中,以作为道具传递,如果它有一个 URL 段,这似乎可以工作,但现在我不能只让我的基本视图返回和site.com/status
我该如何解决这个问题,以便site.com/status
点击我的 index 方法并site.com/status/12345
点击 detail 方法并将 id 作为道具传递?
web.php(路由)
Route::get('/entry/status', 'entry\entryController@index')
->name('entry.status');
Route::get('/entry/status/{id}', 'entry\entryController@details')
->name('entry.status');
控制器.php
public function index() {
return view('entry.status');
}
public function details($id) {
if (request()->wantsJson()) {
return json_encode(entry::getDetails($id));
}
$entryID = json_encode($id);
return view('entry.status')
->with('entryKey', $entryID);
}
status.blade.php
<entry-dashboard :entry-key="{{$entryKey}}"></entry-dashboard>
细节.vue
props: [
'entryKey'
],
created() {
this.setDetailWindow(this.entryKey);
},
setDetailWindow(event) {
this.detailId = event.taskt_id;
axios.get('/entry/status/' + this.detailId)
.then(response => {
...
...
}
解决方案
推荐阅读
- kubernetes - Pod 不在本地路径上写入
- sql - SQL 存储过程参数 - 方法
- c# - c#如何拆分包含Json数据的字符串
- node.js - 定向到文件时如何从Nodejs中的标准输出刷新管道输出
- excel - 如何向现有图表添加额外的 x 轴?
- python - Scrapy/Python/MySQL:将附加项目信息保存在单独的表中的最佳方法是什么?
- c++ - zeroupper 导致不正确的结果
- angular - 角材料选项卡内的角反应形式给出错误
- c# - 在 Asp.net core 的 startup.cs 中获取用户名
- python - Keras:VGG16 中的 model.inputs 是什么