template.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. <script type="text/v-template" id="test">
  7. <p>{{hi}}!</p>
  8. </script>
  9. <script type="text/v-template" id="repeat-template">
  10. <p v-repeat="items">{{title}}</p>
  11. </script>
  12. <!-- content insertion point tests -->
  13. <div id="content">
  14. <my-compponent>
  15. <p class="b">{{b}}</p>
  16. <p class="rest1">rest</p>
  17. <p class="rest2">rest</p>
  18. <p class="a">{{a}}</p>
  19. </my-compponent>
  20. </div>
  21. <script type="text/v-template" id="content-template">
  22. <h1>before</h1>
  23. <content select=".a"></content>
  24. <content select=".b"></content>
  25. <content></content>
  26. <h2>after</h2>
  27. </script>
  28. <!-- content fallback test -->
  29. <div id="fallback"></div>
  30. <script src="../../../dist/vue.js"></script>
  31. <script>
  32. Vue.config({
  33. debug:true
  34. })
  35. // direct usage
  36. var china = new Vue({
  37. id: 'china',
  38. template: '#test'
  39. })
  40. document.body.appendChild(china.$el)
  41. // setting value after compile also works,
  42. // as long as it has appeared in the template
  43. china.hi = '你好'
  44. // extended usage
  45. var Hawaii = Vue.extend({
  46. id: 'hawaii',
  47. template: '#test'
  48. })
  49. var hawaii = new Hawaii()
  50. document.body.appendChild(hawaii.$el)
  51. hawaii.hi = 'Aloha'
  52. // global partial
  53. Vue.partial('global', '#test')
  54. var usa = new Vue({
  55. el: '#usa'
  56. })
  57. usa.hi = 'Hi dude'
  58. // conditional partial
  59. Vue.partial('nope', '<p>nope</p>')
  60. new Vue({
  61. el: '#conditional'
  62. })
  63. // direct partial
  64. var japan = new Vue({
  65. el: '#japan',
  66. partials: {
  67. local: '#test'
  68. }
  69. })
  70. japan.hi = 'こんにちは'
  71. var repeat = new Vue({
  72. el: '#repeat',
  73. partials: {
  74. repeat: '#repeat-template'
  75. },
  76. data: {
  77. items: [{ title: 'Repeat' }]
  78. }
  79. })
  80. Vue.component('my-compponent', {
  81. template: '#content-template',
  82. data: {
  83. a: 'A', b: 'B'
  84. }
  85. })
  86. new Vue({el:'#content'})
  87. new Vue({
  88. el: '#fallback',
  89. template: '<content>This is fallback</content>'
  90. })
  91. </script>