nested-props.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. proto: {
  32. one: function () {
  33. this.a = {
  34. c: 1,
  35. b: {
  36. c: 'one'
  37. }
  38. }
  39. },
  40. two: function () {
  41. this.a.b = {
  42. c: 'two'
  43. }
  44. this.a.c = 2
  45. },
  46. three: function () {
  47. this.a.b.c = 'three'
  48. this.a.c = 3
  49. },
  50. d: {
  51. $get: function () {
  52. return this.msg + (this.a.b.c || '') + (this.a.c || '')
  53. }
  54. },
  55. hidden: {
  56. a: 1,
  57. b: 2
  58. },
  59. sum: {
  60. $get: function () {
  61. return this.hidden.a + this.hidden.b
  62. }
  63. },
  64. four: function () {
  65. this.hidden.a++
  66. },
  67. setEmpty: function () {
  68. this.a.b = {}
  69. },
  70. setEmpty2: function () {
  71. this.a = {}
  72. }
  73. }
  74. })
  75. var app = new Demo({ el: '#a' })
  76. </script>
  77. </body>
  78. </html>