vuex.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <title>vuex</title>
  7. <meta name="description" content="">
  8. <meta name="keywords" content="">
  9. <link href="" rel="stylesheet">
  10. <script src="../js/vue.min.js"></script>
  11. <script src="//cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script>
  12. <script src="//unpkg.com/vuex@3.1.0/dist/vuex.js"></script>
  13. </head>
  14. <body>
  15. <div id="app">
  16. <p>{{ count }}</p>
  17. <p>
  18. <button @click="increment">+</button>
  19. <button @click="decrement">-</button>
  20. </p>
  21. </div>
  22. </body>
  23. <script type="text/javascript">
  24. // make sure to call Vue.use(Vuex) if using a module system
  25. const store = new Vuex.Store({
  26. state: {
  27. count: 0
  28. },
  29. mutations: {
  30. increment: state => state.count++,
  31. decrement: state => state.count--
  32. }
  33. })
  34. new Vue({
  35. el: '#app',
  36. computed: {
  37. count: function() {
  38. return store.state.count;
  39. }
  40. },
  41. methods: {
  42. increment: function() {
  43. store.commit('increment');
  44. },
  45. decrement: function() {
  46. store.commit('decrement');
  47. }
  48. }
  49. })
  50. </script>
  51. </html>