Woj*_*ski 5 elixir phoenix-framework phoenix-live-view
假设我们通过live "/awesome", AwesomeLive.Index, :index.
现在,为了从常规模板或控制器呈现它,我们需要使用live_render/3.
但这行不通,因为: cannot invoke handle_params/3 on AwesomeLive.Index because it is not mounted nor accessed through the router live/3 macro
如何重构handle_params/3?里面是一个自动生成的代码,通过phx.gen.live
@impl true
def handle_params(params, _url, socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
end
Run Code Online (Sandbox Code Playgroud)
里面params是:not_mounted_at_router
编辑:
没有handle_params/3出现中断live_patch/2或其他内容并抛出 JavaScript 错误:
phoenix_live_view.js:1 Uncaught TypeError: Cannot read property 'el' of null
at e.value (phoenix_live_view.js:1)
at phoenix_live_view.js:1
at e.value (phoenix_live_view.js:1)
at e.value (phoenix_live_view.js:1)
at e.value (phoenix_live_view.js:1)
at phoenix_live_view.js:1
at phoenix_live_view.js:1
at Object.callback (phoenix_live_view.js:1)
at e.value (phoenix.js:1)
at phoenix.js:1
Run Code Online (Sandbox Code Playgroud)
版本: