Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <script src="https://cdn.jsdelivr.net/npm/vue"></script>
  <script src="https://unpkg.com/vuex"></script>
  </head>
<body>
<div id="app">
  <p>{{ count }}</p>
  <p>
    <button @click="increment">+</button>
    <button @click="decrement">&minus;</button>
  </p>
  <five/>
</div>
</body>
</html>
 
let store = Vuex.createStore({
  state() {
    return {
      count: 0,
    };
  },
  mutations: {
    increment: state => state.count++,
    decrement: state => state.count--,
  },
});
let app = Vue.createApp({
  store: store,
  computed: {
    count () {
      return store.state.count
    }
  },
  methods: {
    increment () {
      store.commit('increment')
    },
    decrement () {
      store.commit('decrement')
    }
  }
});
app.component('five', {
  template: '<div>{{ isFive }}</div>',
  computed: {
    isFive () {
      return store.state.count === 5 ? 'Five!!!' : 'Not five'
    }
  }
});
app.mount('#app');
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers