tree.js 932 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // demo data
  2. var data = {
  3. name: 'My Tree',
  4. children: [
  5. { name: 'hello' }
  6. ]
  7. }
  8. // define the item component
  9. Vue.component('item', {
  10. template: '#item-template',
  11. props: {
  12. model: Object
  13. },
  14. data: function () {
  15. return {
  16. open: false
  17. }
  18. },
  19. updated: function () {
  20. console.log(this._vnode)
  21. },
  22. computed: {
  23. isFolder: function () {
  24. return this.model.children &&
  25. this.model.children.length
  26. }
  27. },
  28. methods: {
  29. toggle: function () {
  30. if (this.isFolder) {
  31. this.open = !this.open
  32. }
  33. },
  34. changeType: function () {
  35. if (!this.isFolder) {
  36. Vue.set(this.model, 'children', [])
  37. this.addChild()
  38. this.open = true
  39. }
  40. },
  41. addChild: function () {
  42. this.model.children.push({
  43. name: 'new stuff'
  44. })
  45. }
  46. }
  47. })
  48. // boot up the demo
  49. var demo = new Vue({
  50. el: '#demo',
  51. data: {
  52. treeData: data
  53. }
  54. })