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?

More than 5 years have passed since last update.

初心者によるプログラミング学習ログ122日目

0
Posted at

100日チャレンジの122日目

Twitterの100日チャレンジ#タグ、#100DaysOfCode実施中です。
すでに100日超えましたが、継続。

100日チャレンジは、ぱぺまぺの中ではプログラミングに限らず継続学習のために使っています。

122日目は、

学習したことの一部

index.html
<!--複数インスタンスの書き方-->
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="main.css">
    <title>Document</title>
   
</head>
<body>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <div id="app1">
   <p>{{message}}</p>
  </div>
  <div id="app2">
    <P>{{message}}</P>
    <button @click="changeMessage1">インスタンス1のmessageを変更</button>
  </div>

 <script>
   var vm1 = new Vue ({
     el: '#app1',
     data: { 
       message: 'インスタンス1'
     }
   })

   var vm2 = new Vue({
     el: '#app2',
     data: {
       message: 'インスタンス2'
     },
     methods: {
       changeMessage1: function() {
         vm1.message = 'インスタンス2から変更'
       }
     }
   })
  </script>
 </body>
</html>

new Vueでも複数インスタンスつくることは可能。
ただし、なるべくなら同インスタンス内で処理するのが理想。

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?