repeat-object.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <div id="test">
  2. <ul>
  3. <li class="primitive" v-repeat="primitive">{{$key}} {{$value}}</li>
  4. </ul>
  5. <ul>
  6. <li class="obj" v-repeat="obj">{{$key}} {{msg}}</li>
  7. </ul>
  8. <button id="push" v-on="click:t1">push to primitive</button>
  9. <button id="pop" v-on="click:t2">pop from primitive</button>
  10. <button id="shift" v-on="click:t3">shift from object</button>
  11. <button id="unshift" v-on="click:t4">unshift to object</button>
  12. <button id="splice" v-on="click:t5">splice in object</button>
  13. <button id="set" v-on="click:t6">Setting the original object</button>
  14. <p id="primitive">{{primitive}}</p>
  15. <p id="obj">{{obj}}</p>
  16. </div>
  17. <script src="../../../dist/vue.js"></script>
  18. <script>
  19. var test = new Vue({
  20. el: '#test',
  21. data: {
  22. primitive: {
  23. a: 1,
  24. b: 2
  25. },
  26. obj: {
  27. a: { msg: 'hi!' },
  28. b: { msg: 'ha!' }
  29. }
  30. },
  31. methods: {
  32. t1: function () {
  33. this.primitive.$repeater.push({
  34. $key: 'c',
  35. $value: 3
  36. })
  37. },
  38. t2: function () {
  39. this.primitive.$repeater.pop()
  40. },
  41. t3: function () {
  42. this.obj.$repeater.shift()
  43. },
  44. t4: function () {
  45. this.obj.$repeater.unshift({
  46. $key: 'c',
  47. msg: 'ho!'
  48. })
  49. },
  50. t5: function () {
  51. this.obj.$repeater.splice(1, 1, {
  52. $key: 'd',
  53. msg: 'he!'
  54. })
  55. },
  56. t6: function () {
  57. this.primitive.a = 3
  58. this.obj.c = { msg: 'hu!' }
  59. }
  60. }
  61. })
  62. </script>