0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DjangoでVue.jsを使う方法

Posted at

はじめに

DjangoのテンプレートにVue.jsを組み込み体時がある。
ただ普通に組み込もうとするとDjangoとVue.jsとでコンフリクトが起きてしまうので注意(以下で解説)

コンフリクトが起きてしまう原因

DjangoとVue.jsでHTMLに組み込む際に{{}}が混同してしまい、
vue.jsの値が反映されなくなるのが原因

解決策

    <div id="vue-app">
        <h1>[[ myTitle ]]</h1>
    </div>
    <script type="text/javascript">
        let app = new Vue({
          el: "#vue-app",
          delimiters: ['[[', ']]'],  //これが重要
          data: {
            myTitle: 'Hello Vue!',
          },
        });
    </script>

現在、DjangoとVue.jsでのアプリを制作中なのでつまづきやすい部分があればまた投稿します。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?