回答編集履歴
3
修正
test
CHANGED
@@ -30,6 +30,8 @@
|
|
30
30
|
|
31
31
|
```Java
|
32
32
|
|
33
|
+
@CrossOrigin(origins = "http://localhost:3000")
|
34
|
+
|
33
35
|
@PostMapping(value = "/upload", produces = MediaType.APPLICATION_JSON_VALUE)
|
34
36
|
|
35
37
|
public ResponseEntity<Map<String, String>> fileUpload(@RequestParam("name") String name,
|
@@ -118,7 +120,7 @@
|
|
118
120
|
|
119
121
|
|
120
122
|
|
121
|
-
fileupload.vue
|
123
|
+
pages/fileupload.vue
|
122
124
|
|
123
125
|
|
124
126
|
|
@@ -192,7 +194,7 @@
|
|
192
194
|
|
193
195
|
|
194
196
|
|
195
|
-
fileupload.js
|
197
|
+
store/fileupload.js
|
196
198
|
|
197
199
|
|
198
200
|
|
@@ -212,12 +214,16 @@
|
|
212
214
|
|
213
215
|
const file = (event.target.files || event.dataTransfer.files)[0]
|
214
216
|
|
217
|
+
|
218
|
+
|
215
219
|
const formData = new FormData()
|
216
220
|
|
217
221
|
formData.append('name', file.name)
|
218
222
|
|
219
223
|
formData.append('file', file)
|
220
224
|
|
225
|
+
|
226
|
+
|
221
227
|
const response = await this.$axios
|
222
228
|
|
223
229
|
.post('http://localhost:8080/upload', formData, {
|
@@ -226,42 +232,48 @@
|
|
226
232
|
|
227
233
|
})
|
228
234
|
|
235
|
+
.then((response) => {
|
236
|
+
|
237
|
+
context.commit('add', {
|
238
|
+
|
239
|
+
name: response.data.name,
|
240
|
+
|
241
|
+
image: response.data.base64
|
242
|
+
|
243
|
+
})
|
244
|
+
|
245
|
+
})
|
246
|
+
|
229
247
|
.catch((error) => {
|
230
248
|
|
231
249
|
return error.response
|
232
250
|
|
233
251
|
})
|
234
252
|
|
253
|
+
|
254
|
+
|
255
|
+
return response
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
235
|
-
|
263
|
+
export const mutations = {
|
264
|
+
|
236
|
-
|
265
|
+
add(state, payload) {
|
266
|
+
|
267
|
+
state.files.push({
|
268
|
+
|
237
|
-
name:
|
269
|
+
name: payload.name,
|
238
|
-
|
270
|
+
|
239
|
-
image:
|
271
|
+
image: payload.image
|
240
272
|
|
241
273
|
})
|
242
274
|
|
243
|
-
return response
|
244
|
-
|
245
|
-
}
|
275
|
+
}
|
246
|
-
|
276
|
+
|
247
|
-
}
|
277
|
+
}
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
278
|
+
|
252
|
-
|
253
|
-
add(state, payload) {
|
254
|
-
|
255
|
-
state.files.push({
|
256
|
-
|
257
|
-
name: payload.name,
|
258
|
-
|
259
|
-
image: payload.image
|
260
|
-
|
261
|
-
})
|
262
|
-
|
263
|
-
}
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
```
|
279
|
+
```
|
2
修正
test
CHANGED
@@ -154,7 +154,7 @@
|
|
154
154
|
|
155
155
|
<script>
|
156
156
|
|
157
|
-
import { mapState } from 'vuex'
|
157
|
+
import { mapState, mapActions } from 'vuex'
|
158
158
|
|
159
159
|
|
160
160
|
|
@@ -172,33 +172,17 @@
|
|
172
172
|
|
173
173
|
methods: {
|
174
174
|
|
175
|
-
|
175
|
+
...mapActions({
|
176
|
-
|
177
|
-
|
176
|
+
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
this.$store
|
182
|
-
|
183
|
-
|
177
|
+
uploadFile: 'fileupload/uploadFile'
|
184
|
-
|
185
|
-
|
178
|
+
|
186
|
-
|
187
|
-
file
|
188
|
-
|
189
|
-
|
179
|
+
})
|
190
|
-
|
191
|
-
|
180
|
+
|
192
|
-
|
193
|
-
console.log('response', res)
|
194
|
-
|
195
|
-
})
|
196
|
-
|
197
|
-
|
181
|
+
}
|
198
|
-
|
182
|
+
|
199
|
-
|
183
|
+
}
|
200
|
-
|
184
|
+
|
201
|
-
|
185
|
+
</script>
|
202
186
|
|
203
187
|
```
|
204
188
|
|
@@ -224,13 +208,15 @@
|
|
224
208
|
|
225
209
|
export const actions = {
|
226
210
|
|
227
|
-
async uploadFile(context,
|
211
|
+
async uploadFile(context, event) {
|
212
|
+
|
213
|
+
const file = (event.target.files || event.dataTransfer.files)[0]
|
228
214
|
|
229
215
|
const formData = new FormData()
|
230
216
|
|
231
|
-
formData.append('name',
|
217
|
+
formData.append('name', file.name)
|
232
|
-
|
218
|
+
|
233
|
-
formData.append('file',
|
219
|
+
formData.append('file', file)
|
234
220
|
|
235
221
|
const response = await this.$axios
|
236
222
|
|
@@ -278,6 +264,4 @@
|
|
278
264
|
|
279
265
|
}
|
280
266
|
|
281
|
-
|
282
|
-
|
283
|
-
```
|
267
|
+
```
|
1
修正
test
CHANGED
@@ -122,7 +122,7 @@
|
|
122
122
|
|
123
123
|
|
124
124
|
|
125
|
-
```
|
125
|
+
```Vue
|
126
126
|
|
127
127
|
<template>
|
128
128
|
|
@@ -190,13 +190,7 @@
|
|
190
190
|
|
191
191
|
.then((res) => {
|
192
192
|
|
193
|
-
|
193
|
+
console.log('response', res)
|
194
|
-
|
195
|
-
name: res.data.name,
|
196
|
-
|
197
|
-
image: res.data.base64
|
198
|
-
|
199
|
-
})
|
200
194
|
|
201
195
|
})
|
202
196
|
|
@@ -218,7 +212,7 @@
|
|
218
212
|
|
219
213
|
|
220
214
|
|
221
|
-
```
|
215
|
+
```JavaScript
|
222
216
|
|
223
217
|
export const state = () => ({
|
224
218
|
|
@@ -252,6 +246,14 @@
|
|
252
246
|
|
253
247
|
})
|
254
248
|
|
249
|
+
context.commit('add', {
|
250
|
+
|
251
|
+
name: response.data.name,
|
252
|
+
|
253
|
+
image: response.data.base64
|
254
|
+
|
255
|
+
})
|
256
|
+
|
255
257
|
return response
|
256
258
|
|
257
259
|
}
|