Created
July 20, 2020 08:16
-
-
Save iketiunn/dba96ca973816d1e4e929bcd69388a8d to your computer and use it in GitHub Desktop.
liveview example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule HanxinWeb.CounterLive do | |
use HanxinWeb, :live_view | |
def mount(_params, _session, socket) do | |
{:ok, assign(socket, hello: :world, count: 0)} | |
end | |
def render(assigns) do | |
~L""" | |
<H1>Hello <%= assigns.hello %></H1> | |
<p> | |
count: <%= assigns.count %> | |
<div> | |
<button phx-click="+">+</button> | |
<button phx-click="-">-</button> | |
</div> | |
</p> | |
""" | |
end | |
def handle_event("+", _, socket) do | |
{:noreply, assign(socket, count: socket.assigns.count + 1)} | |
end | |
def handle_event("-", _, socket) do | |
{:noreply, assign(socket, count: socket.assigns.count - 1)} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment