0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DjangoでAlpineJSを使う

Posted at

個人メモ

公式 https://alpinejs.dev/essentials/installation の通り、headタグにCDNを記述

templates/base.html
<html>
    <head>
        ...
 
        <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
    </head>
    <body>
        <div class="container">
          {% block content %}{% endblock %}
        </div>
    </body>
</html>

AlpineJSを使いたいところで x-data を記述して使用する

app/create.html
{% extends "base.html" %}

{% block content %}
<div x-data="app()">
    <p>Hello <span x-text="message"></span></p>
</div>

<script>
  const app = () => {
    return {
      message: "AlpineJS"
    }
  }
</script>
{% endblock %}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?