template.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <meta charset="utf-8">
  2. <div id="usa" v-partial="global"></div>
  3. <div id="conditional" v-partial="{{ok ? 'global' : 'nope'}}"></div>
  4. <div id="japan">{{> local}}</div>
  5. <div id="repeat">{{> repeat}}</div>
  6. <div id="yielder"><x-yielder><p>{{a}}</p><p>{{b}}</p></x-yielder></div>
  7. <script type="text/v-template" id="test">
  8. <p>{{hi}}!</p>
  9. </script>
  10. <script type="text/v-template" id="repeat-template">
  11. <p v-repeat="items">{{title}}</p>
  12. </script>
  13. <script type="text/v-template" id="yield-template">
  14. <h1>before</h1>{{>yield}}<h2>after</h2>
  15. </script>
  16. <script src="../../../dist/vue.js"></script>
  17. <script>
  18. Vue.config({
  19. debug:true
  20. })
  21. // direct usage
  22. var china = new Vue({
  23. id: 'china',
  24. template: '#test'
  25. })
  26. document.body.appendChild(china.$el)
  27. // setting value after compile also works,
  28. // as long as it has appeared in the template
  29. china.hi = '你好'
  30. // extended usage
  31. var Hawaii = Vue.extend({
  32. id: 'hawaii',
  33. template: '#test'
  34. })
  35. var hawaii = new Hawaii()
  36. document.body.appendChild(hawaii.$el)
  37. hawaii.hi = 'Aloha'
  38. // global partial
  39. Vue.partial('global', '#test')
  40. var usa = new Vue({
  41. el: '#usa'
  42. })
  43. usa.hi = 'Hi dude'
  44. // conditional partial
  45. Vue.partial('nope', '<p>nope</p>')
  46. new Vue({
  47. el: '#conditional'
  48. })
  49. // direct partial
  50. var japan = new Vue({
  51. el: '#japan',
  52. partials: {
  53. local: '#test'
  54. }
  55. })
  56. japan.hi = 'こんにちは'
  57. var repeat = new Vue({
  58. el: '#repeat',
  59. partials: {
  60. repeat: '#repeat-template'
  61. },
  62. data: {
  63. items: [{ title: 'Repeat' }]
  64. }
  65. })
  66. Vue.component('x-yielder', {
  67. template: '#yield-template',
  68. data: {
  69. a: 'A', b: 'B'
  70. }
  71. })
  72. new Vue({el:'#yielder'})
  73. </script>