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. data: {
  32. hidden: {
  33. a: 1,
  34. b: 2
  35. }
  36. },
  37. computed: {
  38. d: function () {
  39. return this.msg + (this.a.b.c || '') + (this.a.c || '')
  40. },
  41. sum: function () {
  42. return this.hidden.a + this.hidden.b
  43. }
  44. },
  45. methods: {
  46. one: function () {
  47. this.a = {
  48. c: 1,
  49. b: {
  50. c: 'one'
  51. }
  52. }
  53. },
  54. two: function () {
  55. this.a.b = {
  56. c: 'two'
  57. }
  58. this.a.c = 2
  59. },
  60. three: function () {
  61. this.a.b.c = 'three'
  62. this.a.c = 3
  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>