简体   繁体   中英

Why is Phoenix LiveView Function `push_event` undefined?

I want to send an Event from liveView server to the Client, with this funtion:

  def handle_event("test", _, socket) do
    {:noreply, push_event(socket, "testEvent", %{coins: 23, user: "user"})}
  end

This is explained very similar in the docs of liveview. https://hexdocs.pm/phoenix_live_view/js-interop.html But i get this error message:

(CompileError) undefined function push_event/3

Stacktrace:
  │ (elixir 1.10.4) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
  │ (stdlib 3.8) erl_eval.erl:680: :erl_eval.do_apply/6

have i missed some inmport? or what I am doing wrong?

I think the Problem was my version of live view. I had to upgrade:

{:phoenix_live_view, "~> 0.13.0"},

to:

{:phoenix_live_view, "~> 0.14.4"},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM