nested-props.html 2.0 KB

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