檢視來源 Phoenix.LiveView.Controller (Phoenix LiveView v0.20.17)
提供從控制器渲染 LiveView 的輔助工具。
摘要
函式
從 Plug 要求中渲染 LiveView,並從控制器中傳送 HTML 回應。
函式
從 Plug 要求中渲染 LiveView,並從控制器中傳送 HTML 回應。
它也會自動將 @live_module
指定設為要渲染的 LiveView 的值。
選項
請參閱 Phoenix.Component.live_render/3
,以了解所有支援的選項。
範例
defmodule ThermostatController do
use MyAppWeb, :controller
# "use MyAppWeb, :controller" should import Phoenix.LiveView.Controller.
# If it does not, you can either import it there or uncomment the line below:
# import Phoenix.LiveView.Controller
def show(conn, %{"id" => thermostat_id}) do
live_render(conn, ThermostatLive, session: %{
"thermostat_id" => thermostat_id,
"current_user_id" => get_session(conn, :user_id)
})
end
end