partial.js 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var _ = require('../util')
  2. var templateParser = require('../parsers/template')
  3. var vIf = require('./if')
  4. module.exports = {
  5. isLiteral: true,
  6. // same logic reuse from v-if
  7. compile: vIf.compile,
  8. teardown: vIf.teardown,
  9. bind: function () {
  10. var el = this.el
  11. this.start = document.createComment('v-partial-start')
  12. this.end = document.createComment('v-partial-end')
  13. if (el.nodeType !== 8) {
  14. el.innerHTML = ''
  15. }
  16. if (el.tagName === 'TEMPLATE' || el.nodeType === 8) {
  17. _.replace(el, this.end)
  18. } else {
  19. el.appendChild(this.end)
  20. }
  21. _.before(this.start, this.end)
  22. if (!this._isDynamicLiteral) {
  23. this.insert(this.expression)
  24. }
  25. },
  26. update: function (id) {
  27. this.teardown()
  28. this.insert(id)
  29. },
  30. insert: function (id) {
  31. var partial = this.vm.$options.partials[id]
  32. _.assertAsset(partial, 'partial', id)
  33. if (partial) {
  34. this.compile(templateParser.parse(partial))
  35. }
  36. }
  37. }