component.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 alone -->
  7. <div id="with" 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-with="childHi:hi, childName:user.name">
  14. {{childHi}} {{childName}}
  15. </div>
  16. <div id="component-with-sync" v-component="sync" v-with="childHi:hi, childName:user.name"></div>
  17. <!-- conditional component -->
  18. <div id="conditional" v-component="{{ok ? 'my-element' : 'nope'}}"></div>
  19. <!-- conditional component with v-repeat! -->
  20. <div class="repeat-conditional {{type}}" v-repeat="items" v-component="{{type}}"></div>
  21. </div>
  22. <script src="../../../dist/vue.js"></script>
  23. <script>
  24. Vue.config({
  25. debug: true
  26. })
  27. Vue.component('my-avatar', {
  28. template: '{{hi}} {{name}}'
  29. })
  30. Vue.component('my-element', {
  31. template: '{{hi}} {{user.name}}'
  32. })
  33. Vue.component('sync', {
  34. template: '{{childHi}} {{childName}}',
  35. ready: function () {
  36. // should sync back to parent
  37. this.childHi = 'hello'
  38. this.childName = 'Vue'
  39. }
  40. })
  41. Vue.component('nope', {
  42. template: 'NOPE'
  43. })
  44. var app = new Vue({
  45. el: '#test',
  46. data: {
  47. ok: true,
  48. hi: '123',
  49. user: {
  50. name: 'Jack'
  51. },
  52. items: [
  53. { type: 'my-element' },
  54. { type: 'nope' }
  55. ]
  56. }
  57. })
  58. </script>