File tree Expand file tree Collapse file tree 4 files changed +109
-1
lines changed Expand file tree Collapse file tree 4 files changed +109
-1
lines changed Original file line number Diff line number Diff line change @@ -9,3 +9,23 @@ import axios from 'axios'
9
9
export function searchQuestions ( search = 'vue' ) {
10
10
return axios . get ( `${ process . env . API_URL } search?order=desc&sort=votes&intitle=${ search } &site=stackoverflow` )
11
11
}
12
+
13
+ /**
14
+ * @param {number } question id
15
+ * @return {Promise<Object> } List of answers
16
+ * @see {@link https://api.stackexchange.com/docs/answers-on-questions#order=desc&sort=activity&ids=30877491&filter=!9Z(-wzu0T&site=stackoverflow&run=true }
17
+ * @see {@link https://api.stackexchange.com/docs/types/answer }
18
+ */
19
+ export function getAnswers ( id ) {
20
+ return axios . get ( `${ process . env . API_URL } questions/${ id } /answers?order=desc&sort=activity&site=stackoverflow&filter=!9Z(-wzu0T` )
21
+ }
22
+
23
+ /**
24
+ * @param {number } question id
25
+ * @return {Promise<Object> } Question
26
+ * @see {@link https://api.stackexchange.com/docs/questions-by-ids#order=desc&sort=activity&ids=30877491&filter=!-*jbN-o9Aeie&site=stackoverflow&run=true }
27
+ * @see {@link https://api.stackexchange.com/docs/types/question }
28
+ */
29
+ export function getQuestion ( id ) {
30
+ return axios . get ( `${ process . env . API_URL } questions/${ id } ?order=desc&sort=activity&site=stackoverflow&filter=!-*jbN-o9Aeie` )
31
+ }
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div class =" ui container" >
3
+ <div class =" ui items" >
4
+ <div class =" item" >
5
+ <div class =" image" >
6
+ <img :src =" question.owner.profile_image" >
7
+ </div >
8
+ <div class =" content" >
9
+ <a class =" header" >{{ question.title }}</a >
10
+ <div class =" meta" >
11
+ <span >{{ new Date(question.creation_date*1000).toLocaleDateString() }}</span >
12
+ </div >
13
+ <div class =" description" v-html =" question.body" />
14
+ </div >
15
+ </div >
16
+ </div >
17
+ <hr >
18
+ <div class =" ui comments" v-for =" answer in answers" :key =" answer.answer_id" >
19
+ <div class =" comment" >
20
+ <a class =" avatar" >
21
+ <img :src =" answer.owner.profile_image" >
22
+ </a >
23
+ <div class =" content" >
24
+ <a class =" author" >{{ answer.owner.display_name }}</a >
25
+ <div class =" metadata" >
26
+ <div class =" date" >{{ new Date(answer.creation_date*1000).toLocaleDateString() }}</div >
27
+ <div class =" rating" >
28
+ <i class =" star icon" ></i >
29
+ {{ answer.score }} votes
30
+ </div >
31
+ <div v-if =" answer.is_accepted" class =" ui green label" >
32
+ <i class =" checkmark icon" ></i > Accepted
33
+ </div >
34
+ </div >
35
+ <div class =" text" v-html =" answer.body" >
36
+ </div >
37
+ </div >
38
+ </div >
39
+ </div >
40
+ </div >
41
+ </template >
42
+
43
+ <script >
44
+ import { getQuestion , getAnswers } from ' ../api/questions'
45
+
46
+ export default {
47
+ name: ' AnsweredQuestion' ,
48
+ data () {
49
+ return {
50
+ question: {},
51
+ answers: []
52
+ }
53
+ },
54
+ mounted () {
55
+ getQuestion (this .$route .params .questionId ).then (response => {
56
+ this .question = response .data .items [0 ]
57
+ })
58
+ getAnswers (this .$route .params .questionId ).then (response => {
59
+ this .answers = response .data .items .sort ((a , b ) => b .score - a .score )
60
+ })
61
+ }
62
+ }
63
+ </script >
64
+
65
+ <style scoped>
66
+ * >>> pre {
67
+ padding : 16px ;
68
+ overflow : auto ;
69
+ font-size : 85% ;
70
+ line-height : 1.45 ;
71
+ background-color : #f6f8fa ;
72
+ border-radius : 3px ;
73
+ }
74
+
75
+ * >>> * :not (pre ) > code {
76
+ background-color : #f6f8fa ;
77
+ border-radius : 3px ;
78
+ padding : 3px ;
79
+ font-size : 85% ;
80
+ }
81
+ </style >
Original file line number Diff line number Diff line change 15
15
{{ question.title }}
16
16
</div >
17
17
<div v-if =" question.is_answered" class =" actions" >
18
- <a :href =" question.link" >View answers</a >
18
+ <router-link
19
+ :to =" { name: 'AnsweredQuestion', params: { questionId: question.question_id }}"
20
+ >View answers</router-link >
19
21
</div >
20
22
</div >
21
23
</div >
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
2
import Router from 'vue-router'
3
3
import QuestionList from '@/components/QuestionList'
4
+ import AnsweredQuestion from '@/components/AnsweredQuestion'
4
5
5
6
Vue . use ( Router )
6
7
@@ -10,6 +11,10 @@ export default new Router({
10
11
path : '/' ,
11
12
name : 'QuestionList' ,
12
13
component : QuestionList
14
+ } , {
15
+ path : '/:questionId' ,
16
+ name : 'AnsweredQuestion' ,
17
+ component : AnsweredQuestion
13
18
}
14
19
]
15
20
} )
You can’t perform that action at this time.
0 commit comments