nested-props.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8">
  6. <script src="../../../dist/vue.js"></script>
  7. </head>
  8. <body>
  9. <div id="a">
  10. <h1>a.b.c : <span v-text="a.b.c"></span></h1>
  11. <h2>a.c : <span v-text="a.c"></span></h2>
  12. <h3>Computed property that concats the two: <span v-text="d"></span></h3>
  13. <button class="one" v-on="click:one">one</button>
  14. <button class="two" v-on="click:two">two</button>
  15. <button class="three" v-on="click:three">three</button>
  16. <form id="form"><input name="msg" v-model="msg"></form>
  17. <p class="hidden">{{sum}}</p>
  18. <button class="four" v-on="click:four">four</button>
  19. <button class="empty1" v-on="click:setEmpty">empty a.b</button>
  20. <button class="empty2" v-on="click:setEmpty2">empty a</button>
  21. </div>
  22. <script>
  23. Vue.config({debug: true})
  24. var data = { c: 555 }
  25. var Demo = Vue.extend({
  26. lazy: true,
  27. created: function () {
  28. this.msg = 'Yoyoyo'
  29. this.a = data
  30. },
  31. data: {
  32. d: {
  33. $get: function () {
  34. return this.msg + (this.a.b.c || '') + (this.a.c || '')
  35. }
  36. },
  37. hidden: {
  38. a: 1,
  39. b: 2
  40. },
  41. sum: {
  42. $get: function () {
  43. return this.hidden.a + this.hidden.b
  44. }
  45. }
  46. },
  47. methods: {
  48. one: function () {
  49. this.a = {
  50. c: 1,
  51. b: {
  52. c: 'one'
  53. }
  54. }
  55. },
  56. two: function () {
  57. this.a.b = {
  58. c: 'two'
  59. }
  60. this.a.c = 2
  61. },
  62. three: function () {
  63. this.a.b.c = 'three'
  64. this.a.c = 3
  65. },
  66. four: function () {
  67. this.hidden.a++
  68. },
  69. setEmpty: function () {
  70. this.a.b = {}
  71. },
  72. setEmpty2: function () {
  73. this.a = {}
  74. }
  75. }
  76. })
  77. var app = new Demo({ el: '#a' })
  78. </script>
  79. </body>
  80. </html>