Skip to content

Instantly share code, notes, and snippets.

@mcanv
Created December 1, 2020 18:22
Show Gist options
  • Select an option

  • Save mcanv/6ad8a86fbdc5b17eecbdc3570da50027 to your computer and use it in GitHub Desktop.

Select an option

Save mcanv/6ad8a86fbdc5b17eecbdc3570da50027 to your computer and use it in GitHub Desktop.
AlpineJS Hello World
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AlpineJS Hello World</title>
</head>
<body>
<div x-data="app()">
<button x-on:click="toggleMessage()" x-text="messageShow ? 'Hide': 'Show'"></button>
<h1 x-show="messageShow" x-text="message"></h1>
</div>
<script>
function app() {
return {
message: 'Hello World',
messageShow: true,
toggleMessage() {
this.messageShow = !this.messageShow
}
}
}
</script>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment