Created
October 1, 2021 21:51
-
-
Save ftes/4cf79658e7394821eca7aeb24297d5a1 to your computer and use it in GitHub Desktop.
alpine.js + liveview
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 PetalsDragNDropWeb.PageLive do | |
use PetalsDragNDropWeb, :live_view | |
data world, :string, default: "world!" | |
@impl true | |
def render(assigns) do | |
~F""" | |
<div | |
id="page" | |
:hook="Page" | |
x-data | |
x-init="setTimeout(() => { pageHook.pushEvent('set_world', 'WORLD!') }, 1000)" | |
class="h-screen flex justify-center items-center font-bold text-3xl" | |
> | |
Hello {@world} | |
</div> | |
""" | |
end | |
@impl true | |
def handle_event("set_world", value, socket) do | |
{:noreply, assign(socket, world: value)} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment