LoginSignup
0
0

More than 1 year has passed since last update.

Vue のリアクティブシステム

Posted at

vueのリアクティブシステムとは

new Vue({
  el: '#app',
 data: {
    fruits: ['りんご','バナナ','キィウイ']
       },
    methods:{
    remove: function(),
      this.fruits.shift()
      }
    }
})

配列の中身を変えるとそれに従って表示されるフルーツの中身も変わるということ。
ここからわかるルール。

リアクティブさせたいのなら初めからデータ内部にリアクティブにしたいプロパティを含めておくこと。

viewはviewインスタンスを見渡してそこにあるプロパティに対してsetterとgetterを用意する。

以下のインスタンスのvm1をコンソールで中身を見てみる。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
  <div id="app1">
     <p>{{message}}</p>
  </div>
<script>
  var vm1 = new Vue({
    el: '#app1',
    data: {
      me
ssage: 'app1'
    }
  })

  console.log(vm1)
</script>
</body>
</html>

のぞくと

20210507-214239.png

下の方に
get message
set message
があるのがわかる。これによってリアクティブシステムは動いてます。

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