在实时视图中,我有这个片段:
<div id="chat"><%= live_render(@socket, MyAppWeb.ChatLive.Index, id: "watch-chats", guest: @guest) %></div>
在 ChatLive.Index 我有这个挂载功能:
@impl true
def mount(%{"guest_id" => guest_id}, _session, socket) do
...
end
def mount(:not_mounted_at_router, session, socket) do
mount(%{"guest_id" => socket.assigns.guest.id}, session, socket)
end
但它给出了这个错误:
key :guest not found in: %{flash: %{}, live_action: nil}
与mount(%{"guest_id" => socket.assigns.guest.id}, session, socket)
.
如何将诸如来宾之类的参数传递给live_render
调用并在mount
函数中提取它?