Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <div id="app">
  2.  
  3. <!-- NAVIGATION -->
  4. <div class="nav">
  5. <nav v-for="nav in navs"
  6. v-bind:key="nav"
  7. v-bind:class="['nav-button', { active: currentNav === nav }]"
  8. v-on:click="currentNav = nav">
  9. {{ nav }}
  10. </nav>
  11. </div>
  12.  
  13. <!-- CONTENT COMPONENT-->
  14. <transition name="flipit">
  15. <component
  16. v-bind:is="contentComponent"
  17. class="contentDetails">
  18. </component>
  19. </transition>
  20.  
  21. </div>
  22.  
  23.  
  24.  
  25. Vue.component('nav-home', {
  26. template: `<div>
  27. <h1> Home component </h1>
  28. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
  29.  
  30. <!-- banner -->
  31. <product-banner
  32. v-for="banner in banners"
  33. v-bind:key="banner.id"
  34. v-bind:banner="banner">
  35. </product-banner>
  36.  
  37. <!-- post -->
  38. <blog-post
  39. v-for="post in posts"
  40. v-bind:key="post.id"
  41. v-bind:post="post">
  42. </blog-post>
  43.  
  44. </div>`
  45. })
  46.  
  47. Vue.component('blog-post', {
  48. props: ['posts'],
  49. template: `<h3>{{posts.title}}</h3>`
  50. })
  51.  
  52. Vue.component('product-banner', {
  53. props: ['banner'],
  54. template: `<div id="product-banner">
  55. <div class="product-container">
  56. <h2>{{banner.title}}</h2>
  57. <p>{{banner.content}}</p>
  58. </div>
  59. </div>`
  60. })
  61.  
  62. Vue.directive('focus', {
  63. inserted: function(el) {
  64. el.focus();
  65. }
  66. })
  67.  
  68. new Vue({
  69. el: '#app',
  70. data: {
  71. currentNav: 'Home',
  72. navs: ['Home'],
  73. posts: [
  74. { id: 1, title: 'Title one' },
  75. { id: 2, title: 'Title two' },
  76. { id: 3, title: 'Title three' }
  77. ],
  78. banners: [
  79. {id: 1, title: 'Title 1', content: 'Content 1'},
  80. {id: 2, title: 'Title 2', content: 'Content 2'},
  81. {id: 3, title: 'Title 3', content: 'Content 3'}
  82. ]
  83. },
  84. computed: {
  85. contentComponent: function() {
  86. return 'nav-' + this.currentNav.toLowerCase()
  87. }
  88. },
  89. directive: {
  90. focus: {
  91. inserted: function(el) {
  92. el.focus()
  93. }
  94. }
  95. }
  96.  
  97. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement