Advertisement
Guest User

Untitled

a guest
Jun 14th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <template>
  2. <div class="container">
  3. <div class="row">
  4. <div class="col-12">
  5. <button class="btn btn-primary" @click="selectedComponent='app-quote'">Quote</button>
  6. <button class="btn btn-primary" @click="selectedComponent='app-new'">New</button>
  7. <button class="btn btn-primary" @click="selectedComponent='app-author'">Author</button>
  8. <hr>
  9. <!-- keep alive will prevent dynamic components from being destroyed when switching views -->
  10. <keep-alive>
  11. <component :is="selectedComponent">
  12. <!-- this html will get passed to the app-quote for rendering using a slot, now you can set the data on the elements here -->
  13. <h2 slot="title">{{ title }}</h2>
  14. <p>A Quote</p>
  15. </component>
  16. </keep-alive>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21.  
  22. <script>
  23. import Quote from './components/Quote';
  24. import New from './components/New';
  25. import Author from './components/Author';
  26.  
  27. export default {
  28. data: function(){
  29. return {
  30. title: 'My Quotes',
  31. selectedComponent: 'app-quote'
  32. }
  33. },
  34. components: {
  35. 'app-quote': Quote,
  36. 'app-new': New,
  37. 'app-author': Author
  38. }
  39. }
  40. </script>
  41.  
  42. <style>
  43. /* this apply but can be overwritten by the child */
  44. h2 {
  45. color: firebrick;
  46. }
  47. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement