Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <template>
  2. <b-container v-if="is_loaded">
  3. <b-row>
  4. <b-col>
  5.  
  6. <div v-html="article"></div>
  7.  
  8. </b-col>
  9. <b-col>
  10. <a href="#" @click.prevent="article = getArticle()" class="button button-primary">Reload</a>
  11. </b-col>
  12.  
  13.  
  14. </b-row>
  15. </b-container>
  16. </template>
  17.  
  18. <script>
  19.  
  20. let project = {
  21. id:'12g65-13h7-138jh-1d5fg',
  22. version:0.1,
  23. name: 'Some name',
  24. intro:{
  25. title:['intro title one', 'intro title two'],
  26. subtitle:['sub 1', 'sub 2'],
  27. content:['para 1', 'para 2']
  28. },
  29. summary:{
  30. title:['summary title one', 'summary title two'],
  31. subtitle:['sub 1', ''],
  32. content:['para 1', 'para 2']
  33. },
  34. items:[
  35. {
  36. id:1,
  37. title:['item 1 title 1', 'item 1 title 2'],
  38. subtitle:['', 'item 1 sub 2'],
  39. content:['para 1', 'para 2']
  40. },
  41. {
  42. id:2,
  43. title:['item 2 title 1', 'item 2 title 2'],
  44. subtitle:['item 2 sub 1', 'item 2 sub 2'],
  45. content:['para 1', 'para 2']
  46. },
  47. ]
  48. }
  49.  
  50. export default {
  51.  
  52.  
  53. data(){
  54. return {
  55. project:null,
  56. variation_count:0,
  57. item_count:0,
  58. reload_count:0,
  59. article:'',
  60. is_loaded:false
  61. }
  62. },
  63. mounted(){
  64. this.project = project;
  65. this.variation_count = project.intro.title.length;
  66. this.item_count = project.items.length;
  67. this.article = this.getArticle();
  68. this.is_loaded = true;
  69.  
  70. },
  71. computed:{
  72.  
  73.  
  74. },
  75. methods:{
  76. getIntro(){
  77. let title = this.project.intro.title[this.getRandomIndex()];
  78. let subtitle = this.project.intro.subtitletitle[this.getRandomIndex()];
  79. },
  80.  
  81. getRandomIndex(){
  82. return Math.floor(Math.random() * this.variation_count);
  83. },
  84.  
  85. getRandomItems(){
  86. let items = this.project.items;
  87. items.sort((a,b) => 0.5 - Math.random());
  88. return items.slice(0, Math.floor(Math.random() * this.item_count))
  89. },
  90. getArticle(){
  91. //yuck, POC only
  92. console.log('getArticle');
  93. let html='';
  94. html +=`<h1>${this.project.intro.title[this.getRandomIndex()]}</h1>`;
  95. html += `<p><b>${this.project.intro.subtitle[this.getRandomIndex()]}</b></p>`;
  96. html += `<p>${this.project.intro.content[this.getRandomIndex()]}</p>`;
  97.  
  98. return html;
  99. }
  100. }
  101. }
  102. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement