Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.2/vue.min.js"></script>
</head>
<body>
<div id="app">
  Person: {{ shownPerson.name }}
  <button @click="nextPerson">Next Person</button>
</div>
<script>
new Vue({
  el: '#app',
  data: {
    shownPersonIndex: 0,
    persons: [{
        id: 1,
        name: 'Alex'
      },
      {
        id: 2,
        name: 'Bob'
      },
      {
        id: 3,
        name: 'Chris'
      }
    ],
  },
  methods: {
    nextPerson: function() {
      this.shownPersonIndex++;
      
      if(this.shownPersonIndex == this.persons.length) {
        this.shownPersonIndex = 0;
      }
    }
  },
  computed: {
    shownPerson: function() {
      return this.persons[this.shownPersonIndex];
    }
  }
});
</script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers