从remix中获取数据
我正在探索 remix.run 并制作示例应用程序。我遇到了一个困扰我一段时间的问题。如果我错了,请纠正我:action()
用于处理表单提交,而loader()
最初用于获取数据。 对于我的应用程序,我使用Mongoose在query.server.ts
文件中连接mongodb,定义的模型和定义的查询功能。我想通过query.server.ts
文件中定义的函数从数据库中获取数据,然后单击UI上的图像。不使用表格,我该怎么做?我无法在不知道用户点击哪些图像的情况下预取数据。
I was exploring Remix.run and making a sample app. I came across an issue that has been bothering me for some time now. Correct me if I am wrong: action()
is for handling Form submission, and loader()
is for fetching data initially.
For my application, I used mongoose to connect MongoDB, defined models, and defined querying function in a query.server.ts
file. I want to fetch data from the database through a function defined in the query.server.ts
file when an image is clicked on the UI. How can I do that without using forms? I cannot pre-fetch the data without knowing what image was clicked by the user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个资源路线。这些就像常规路线,但不要导出默认组件(否UI)。
您可以使用
usefetcher
挂钩并调用fetcher.load()
来调用您的资源路由。数据在fetcher.data
中。You can create a resource route. These are like regular routes, but don't export a default component (no UI).
You can use the
useFetcher
hook and callfetcher.load()
to call your resource route. The data is infetcher.data
.