質問編集履歴

7

ソースコード

2019/04/01 05:20

投稿

anusama
anusama

スコア13

test CHANGED
File without changes
test CHANGED
@@ -60,36 +60,6 @@
60
60
 
61
61
  <div class="SearchResults">
62
62
 
63
-
64
-
65
-   <div class="text-center mt-5 pt-5" v-if="!loading && completed && listings.length === 0">
66
-
67
- <h1>お探しモノは見つかりませんでした</h1>
68
-
69
- </div>
70
-
71
-
72
-
73
-   <div id="searchList">
74
-
75
- <article v-for="listing in listings" :key="listing.id">
76
-
77
- <figure class="tmbPic">
78
-
79
- <a :href="'/pens/' + listing.id" target="_blank">
80
-
81
- <img :src="topImage(listing)" alt="">
82
-
83
- </a>
84
-
85
- </figure>
86
-
87
- </article>
88
-
89
- </div>   
90
-
91
-
92
-
93
63
  <div class="text-center mb-5 pb-5" v-if=" ">
94
64
 
95
65
  <figure><img src="./hoge.png"></figure>
@@ -112,167 +82,19 @@
112
82
 
113
83
  <script>
114
84
 
115
- import $ from 'jquery'
116
-
117
85
  const axios = require('axios');
118
-
119
-
120
86
 
121
87
 
122
88
 
123
89
  export default {
124
90
 
125
- props: {
126
-
127
- 'bus': {
128
-
129
- type: Object,
130
-
131
- default: null
132
-
133
- }
134
-
135
- },
136
-
137
-
138
-
139
- data () {
140
-
141
- return {
142
-
143
- loading: false,
144
-
145
- completed: false,
146
-
147
- listings: [],
148
-
149
- listingStatusTexts: []
150
-
151
- }
152
-
153
- },
154
-
155
-
156
-
157
- mounted () {
158
-
159
- this.bus.$on('submit', this.onSubmit.bind(this))
160
-
161
- this.bus.$on('fetched', this.onFetched.bind(this))
162
-
163
- this.bus.$on('fetchedLoadMore', this.onFetchedLoadMore.bind(this))
164
-
165
- $(document.body).on('scroll.loadMore', this.handleScroll)
166
-
167
- },
168
-
169
-
170
-
171
- destroyed () {
172
-
173
- $(document.body).off('scroll.loadMore')
174
-
175
- },
176
-
177
-
178
-
179
91
  methods: {
180
-
181
- handleScroll (e) {
182
-
183
- if ((e.target.scrollTop + e.target.offsetHeight) >= (e.target.scrollHeight - 100)) {
184
-
185
- this.loadMore()
186
-
187
- }
188
-
189
- },
190
-
191
-
192
-
193
- onSubmit () {
194
-
195
- this.loading = true
196
-
197
- this.listings = []
198
-
199
- },
200
-
201
-
202
-
203
- onFetched (results) {
204
-
205
- this.loading = false
206
-
207
- const newListings = results.result || results.listings
208
-
209
- this.listings = newListings
210
-
211
- this.completed = newListings.length < 30
212
-
213
- this.listingStatusTexts = results.listing_status_texts
214
-
215
- },
216
-
217
-
218
-
219
- onFetchedLoadMore (results) {
220
-
221
- this.loading = false
222
-
223
- const newListings = results.result || results.listings
224
-
225
- this.listings.push(...newListings)
226
-
227
- this.completed = newListings.length < 30
228
-
229
- this.listingStatusTexts = results.listing_status_texts
230
-
231
- },
232
-
233
-
234
-
235
- topImage (listing) {
236
-
237
- if (listing.images.length === 0) {
238
-
239
- return './hoge.jpg'
240
-
241
- }
242
-
243
- return listing.images[0].user_image.url
244
-
245
- },
246
-
247
-
248
-
249
- loadMore () {
250
-
251
- if (!this.completed && !this.loading) {
252
-
253
- this.loading = true
254
-
255
- this.bus.$emit('loadMore')
256
-
257
- }
258
-
259
- },
260
-
261
-
262
-
263
- statusLabel (status) {
264
-
265
- return this.listingStatusTexts[status] || status
266
-
267
- },
268
-
269
-
270
92
 
271
93
  //200以外はエラー
272
94
 
273
95
  SearchError () {
274
96
 
275
- axios.get('https://hoge/search').catch(function (error) {
97
+ axios.get('https://hoge/fuga').catch(function (error) {
276
98
 
277
99
  if (error.response) {
278
100
 
@@ -283,8 +105,6 @@
283
105
  });
284
106
 
285
107
  }
286
-
287
-
288
108
 
289
109
  }
290
110
 

6

ソースコード

2019/04/01 05:20

投稿

anusama
anusama

スコア13

test CHANGED
File without changes
test CHANGED
@@ -272,7 +272,7 @@
272
272
 
273
273
  SearchError () {
274
274
 
275
- axios.get('https://ancar.senna/cars/search').catch(function (error) {
275
+ axios.get('https://hoge/search').catch(function (error) {
276
276
 
277
277
  if (error.response) {
278
278
 

5

ソースコード

2019/03/29 09:24

投稿

anusama
anusama

スコア13

test CHANGED
File without changes
test CHANGED
@@ -60,6 +60,36 @@
60
60
 
61
61
  <div class="SearchResults">
62
62
 
63
+
64
+
65
+   <div class="text-center mt-5 pt-5" v-if="!loading && completed && listings.length === 0">
66
+
67
+ <h1>お探しモノは見つかりませんでした</h1>
68
+
69
+ </div>
70
+
71
+
72
+
73
+   <div id="searchList">
74
+
75
+ <article v-for="listing in listings" :key="listing.id">
76
+
77
+ <figure class="tmbPic">
78
+
79
+ <a :href="'/pens/' + listing.id" target="_blank">
80
+
81
+ <img :src="topImage(listing)" alt="">
82
+
83
+ </a>
84
+
85
+ </figure>
86
+
87
+ </article>
88
+
89
+ </div>   
90
+
91
+
92
+
63
93
  <div class="text-center mb-5 pb-5" v-if=" ">
64
94
 
65
95
  <figure><img src="./hoge.png"></figure>
@@ -76,21 +106,173 @@
76
106
 
77
107
 
78
108
 
109
+
110
+
111
+
112
+
79
113
  <script>
80
114
 
115
+ import $ from 'jquery'
116
+
81
117
  const axios = require('axios');
82
118
 
83
119
 
84
120
 
121
+
122
+
85
123
  export default {
86
124
 
125
+ props: {
126
+
127
+ 'bus': {
128
+
129
+ type: Object,
130
+
131
+ default: null
132
+
133
+ }
134
+
135
+ },
136
+
137
+
138
+
139
+ data () {
140
+
141
+ return {
142
+
143
+ loading: false,
144
+
145
+ completed: false,
146
+
147
+ listings: [],
148
+
149
+ listingStatusTexts: []
150
+
151
+ }
152
+
153
+ },
154
+
155
+
156
+
157
+ mounted () {
158
+
159
+ this.bus.$on('submit', this.onSubmit.bind(this))
160
+
161
+ this.bus.$on('fetched', this.onFetched.bind(this))
162
+
163
+ this.bus.$on('fetchedLoadMore', this.onFetchedLoadMore.bind(this))
164
+
165
+ $(document.body).on('scroll.loadMore', this.handleScroll)
166
+
167
+ },
168
+
169
+
170
+
171
+ destroyed () {
172
+
173
+ $(document.body).off('scroll.loadMore')
174
+
175
+ },
176
+
177
+
178
+
87
179
  methods: {
88
180
 
181
+ handleScroll (e) {
182
+
183
+ if ((e.target.scrollTop + e.target.offsetHeight) >= (e.target.scrollHeight - 100)) {
184
+
185
+ this.loadMore()
186
+
187
+ }
188
+
189
+ },
190
+
191
+
192
+
193
+ onSubmit () {
194
+
195
+ this.loading = true
196
+
197
+ this.listings = []
198
+
199
+ },
200
+
201
+
202
+
203
+ onFetched (results) {
204
+
205
+ this.loading = false
206
+
207
+ const newListings = results.result || results.listings
208
+
209
+ this.listings = newListings
210
+
211
+ this.completed = newListings.length < 30
212
+
213
+ this.listingStatusTexts = results.listing_status_texts
214
+
215
+ },
216
+
217
+
218
+
219
+ onFetchedLoadMore (results) {
220
+
221
+ this.loading = false
222
+
223
+ const newListings = results.result || results.listings
224
+
225
+ this.listings.push(...newListings)
226
+
227
+ this.completed = newListings.length < 30
228
+
229
+ this.listingStatusTexts = results.listing_status_texts
230
+
231
+ },
232
+
233
+
234
+
235
+ topImage (listing) {
236
+
237
+ if (listing.images.length === 0) {
238
+
239
+ return './hoge.jpg'
240
+
241
+ }
242
+
243
+ return listing.images[0].user_image.url
244
+
245
+ },
246
+
247
+
248
+
249
+ loadMore () {
250
+
251
+ if (!this.completed && !this.loading) {
252
+
253
+ this.loading = true
254
+
255
+ this.bus.$emit('loadMore')
256
+
257
+ }
258
+
259
+ },
260
+
261
+
262
+
263
+ statusLabel (status) {
264
+
265
+ return this.listingStatusTexts[status] || status
266
+
267
+ },
268
+
269
+
270
+
89
271
  //200以外はエラー
90
272
 
91
273
  SearchError () {
92
274
 
93
- axios.get('https://hoge/search').catch(function (error) {
275
+ axios.get('https://ancar.senna/cars/search').catch(function (error) {
94
276
 
95
277
  if (error.response) {
96
278
 
@@ -102,6 +284,8 @@
102
284
 
103
285
  }
104
286
 
287
+
288
+
105
289
  }
106
290
 
107
291
  }

4

文章変更

2019/03/28 14:47

投稿

anusama
anusama

スコア13

test CHANGED
File without changes
test CHANGED
@@ -35,6 +35,14 @@
35
35
  2.
36
36
 
37
37
  `template`内の`v-if="xxxx"`にどのように繋げれば、描画することができるのか不明。
38
+
39
+
40
+
41
+ `methods:`で200以外のステータスコードを着火とすれば、
42
+
43
+ `v-if`で描画に繋げることができるのではないか
44
+
45
+ と考え試しておりますが、適切な実装手段がみえていない状態です。
38
46
 
39
47
 
40
48
 

3

タイトル変更

2019/03/28 14:22

投稿

anusama
anusama

スコア13

test CHANGED
@@ -1 +1 @@
1
- Vue.jsで500エラーがでた場合、エラー画像を描画したい
1
+ 500エラーがでた場合、Vue.jsでエラー画像を描画したい(axios利用)
test CHANGED
File without changes

2

参考の明瞭化

2019/03/28 13:39

投稿

anusama
anusama

スコア13

test CHANGED
File without changes
test CHANGED
@@ -114,4 +114,16 @@
114
114
 
115
115
  `axios`を利用するだろうと推測し、ここまで進みましたが詰まってしまいました。
116
116
 
117
- 私の実力不足で理解が及ばす、的はずれな書き方をしていると思いますが、どうぞお力をお貸していただければと思います。
117
+ 私の実力不足で理解が及ばす、的はずれな書き方をしていると思いますが、
118
+
119
+ どうぞお力をお貸していただければと思います。
120
+
121
+
122
+
123
+ 主に参考にしたサイト
124
+
125
+ https://www.yoheim.net/blog.php?q=20170801
126
+
127
+ https://qiita.com/kimullaa/items/6e7bcc3779c32a383826
128
+
129
+ https://qiita.com/shisama/items/61cdcc09dc69fd8d3127

1

文章変更

2019/03/28 13:35

投稿

anusama
anusama

スコア13

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  現状`axios`を利用し、200系以外はステータスコードを吐く仕組みは、なんとか調べてできた段階です。
18
18
 
19
- 問題点は主に2点す。
19
+ 問題点は主に2点あると考えています。
20
20
 
21
21
 
22
22