用惯性JS传递时,在VUE中无法获得的道具无法访问
我有一个inertiajs应用程序,其中我称之为具有以下链接的组件:
<Link href="/explore-data"
class="rounded-lg bg-blue-500 hover:bg-blue-200 text-white text-md font-semibold tracking-wide p-2"
:data="{ selectedIds: selectedIds }">
Proceed
</Link>
然后,在我的web.php文件中,我将其传递给下一个组件,如下所示:
Route::get('/explore-data', function (\Illuminate\Http\Request $request) {
return Inertia::render('ExploreData', [
'cities' => \App\Models\City::all(),
'selectedIds' => $request->selectedIds
]);
});
在我的exploredata组件中,我尝试访问SelectedIDS我创建的钩子中的支柱,但是将其打印出来,这表明它是无效的。奇怪的是,这仅发生在我的服务器上,当我在Local主持器上这样做时,它可以正常工作。这是我声明道具并尝试在探索的组件中称呼它的方式:
export default {
props: {
selectedIds: Object,
cities: Object
},
...
created() {
let t = this
console.log('Selected IDS: ')
console.log(this.selectedIds) // this gives me NULL on server, but not on localhost
this.selectedIds.forEach(function(item) {
// do something with my selectedIds
})
....
有人知道这里可能发生什么以及如何修复它吗?
I've got an Inertiajs app in which I call a component with the following link:
<Link href="/explore-data"
class="rounded-lg bg-blue-500 hover:bg-blue-200 text-white text-md font-semibold tracking-wide p-2"
:data="{ selectedIds: selectedIds }">
Proceed
</Link>
Then, in my web.php file I pass it to the next component as a prop as follows:
Route::get('/explore-data', function (\Illuminate\Http\Request $request) {
return Inertia::render('ExploreData', [
'cities' => \App\Models\City::all(),
'selectedIds' => $request->selectedIds
]);
});
In my ExploreData component, I try to access the selectedIds prop in my created hook, but printing it out shows me that it's null. What is strange is that this only happens on my server, when I do this on localhost it works fine. Here is how I declare the prop and try to call it in the ExploreData component:
export default {
props: {
selectedIds: Object,
cities: Object
},
...
created() {
let t = this
console.log('Selected IDS: ')
console.log(this.selectedIds) // this gives me NULL on server, but not on localhost
this.selectedIds.forEach(function(item) {
// do something with my selectedIds
})
....
Does someone know what could be happening here and how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现这实际上是NGINX的问题,而不是惯性 / VUE的问题。我的nginx配置具有以下设置,该设置指定了如何处理查询字符串:
我必须将其更改为以下内容:
我不声称了解Nginx,但我只知道第一个设置没有拾取查询字符串适当地。
I found that this was actually an issue with Nginx and not with Inertia / Vue. My nginx config had the following setting that specifies how to handle the query string:
And I had to change it to the following:
I don't claim to understand nginx, but I just know the first setting didn't pick up the query string properly.