Advertisement
Guest User

Untitled

a guest
May 27th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.     <div class="home">
  3.         <div class="container">
  4.             <div v-for="question in questions" :key="question.pk">
  5.                 <p class="mb-0">Posted by:
  6.                     <span class="question-author">{{ question.author }}</span>
  7.                 </p>
  8.                 <h2>
  9.                     <router-link :to="{name: 'question', params: {slug: question.slug}}" class="question-link">
  10.                         {{ question.content }}
  11.                     </router-link>
  12.                 </h2>
  13.                 <p>Answers: {{question.answers_count}}</p>
  14.                 <hr>
  15.             </div>
  16.         </div>
  17.     </div>
  18. </template>
  19.  
  20. <script>
  21.     import {apiService} from "@/common/api.service";
  22.  
  23.     export default {
  24.         name: "home",
  25.         data() {
  26.             return {
  27.                 questions: []
  28.             }
  29.         },
  30.  
  31.         methods: {
  32.             getQuestions() {
  33.                 let endpoint = "/api/questions/";
  34.                 apiService(endpoint)
  35.                     .then(data => {
  36.                         this.questions.push(...data.results)
  37.                     })
  38.             }
  39.         },
  40.         created() {
  41.             this.getQuestions()
  42.         }
  43.     };
  44. </script>
  45.  
  46. <style scoped>
  47.     .question-author {
  48.         font-weight: bold;
  49.         color: red;
  50.     }
  51.  
  52.     .question-link {
  53.         font-weight: bold;
  54.         color: black;
  55.     }
  56.  
  57.     .question-link:hover {
  58.         color: #343A40;
  59.         text-decoration: none;
  60.     }
  61. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement