extend.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <div id="log"></div>
  2. <div id="test">
  3. <div class="dir" v-hola="dirMsg"></div>
  4. <div class="filter">{{filterMsg | nodigits}}</div>
  5. <div class="partial" v-partial="partial-test"></div>
  6. <div class="vm" v-component="vm-test">{{vmMsg}}</div>
  7. <div class="vm-w-model" v-component="vm-w-model" v-with="vmData">{{selfMsg + msg}}</div>
  8. </div>
  9. <div id="child">
  10. <div class="cvm" v-component="vm-test">{{vmMsg}}</div>
  11. </div>
  12. <script src="../../../dist/vue.js"></script>
  13. <script>
  14. Vue.config({debug:true})
  15. var log = document.getElementById('log')
  16. var T = Vue.extend({
  17. created: function () {
  18. log.textContent += ' T created'
  19. },
  20. ready: function () {
  21. log.textContent += ' T ready'
  22. },
  23. components: {
  24. 'vm-test': {
  25. data: {
  26. vmMsg: 'component works'
  27. }
  28. },
  29. 'vm-w-model': {
  30. data : {
  31. selfMsg: 'component with model '
  32. }
  33. }
  34. },
  35. partials: {
  36. 'partial-test': '{{partialMsg}}'
  37. },
  38. directives: {
  39. hola: function (value) {
  40. this.el.innerHTML = value + ' works'
  41. }
  42. },
  43. filters: {
  44. nodigits: function (value) {
  45. return value.replace(/\d/g, '')
  46. }
  47. }
  48. })
  49. var C = T.extend({
  50. created: function () {
  51. log.textContent += ' C created'
  52. },
  53. ready: function () {
  54. log.textContent += ' C ready'
  55. }
  56. })
  57. var test = new T({
  58. el: '#test',
  59. data: {
  60. dirMsg: 'directive',
  61. filterMsg: 'fi43l132ter5 w12345orks',
  62. partialMsg: 'partial works',
  63. vmData: {
  64. msg: 'works'
  65. }
  66. }
  67. })
  68. new C({
  69. el: '#child'
  70. })
  71. </script>