component.html 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <div id="test">
  2. <!-- v-component + v-with -->
  3. <div id="component-and-with" v-component="my-avatar" v-with="user"></div>
  4. <!-- custom element + v-with -->
  5. <my-avatar id="element-and-with" v-with="user"></my-avatar>
  6. <!-- v-with with default Ctor -->
  7. <div id="with" v-component v-with="user">{{hi}} {{name}}</div>
  8. <!-- v-component alone -->
  9. <div id="component" v-component="my-element"></div>
  10. <!-- custom element alone -->
  11. <my-element id="element"></my-element>
  12. <!-- v-with + binding sync -->
  13. <div id="with-sync" v-component v-with="childHi:hi, childName:user.name">
  14. {{childHi}} {{childName}}
  15. </div>
  16. <!-- conditional component -->
  17. <div id="conditional" v-component="{{ok ? 'my-element' : 'nope'}}"></div>
  18. <!-- this one will change everything for everyone else... -->
  19. <div id="component-with-sync" v-component="sync" v-with="childHi:hi, childName:user.name"></div>
  20. <!-- conditional component with v-repeat! -->
  21. <div class="repeat-conditional {{type}}" v-repeat="items" v-component="{{type}}"></div>
  22. </div>
  23. <script src="../../../dist/vue.js"></script>
  24. <script>
  25. // Vue.config({
  26. // debug: true
  27. // })
  28. Vue.component('my-avatar', {
  29. template: '{{hi}} {{name}}'
  30. })
  31. Vue.component('my-element', {
  32. template: '{{hi}} {{user.name}}'
  33. })
  34. Vue.component('sync', {
  35. template: '{{childHi}} {{childName}}',
  36. ready: function () {
  37. // should sync back to parent
  38. this.childHi = 'hello'
  39. this.childName = 'Vue'
  40. }
  41. })
  42. Vue.component('nope', {
  43. template: 'NOPE'
  44. })
  45. var app = new Vue({
  46. el: '#test',
  47. data: {
  48. ok: true,
  49. hi: '123',
  50. user: {
  51. name: 'Jack'
  52. },
  53. items: [
  54. { type: 'my-element' },
  55. { type: 'nope' }
  56. ]
  57. }
  58. })
  59. </script>