回答編集履歴

3

ソース修正

2019/03/08 04:52

投稿

sauzar18
sauzar18

スコア163

test CHANGED
@@ -126,7 +126,7 @@
126
126
 
127
127
  let file = e.target.files[0]
128
128
 
129
- this.$set(this.images, i, window.URL.createObjectURL(file))
129
+ if (file) this.$set(this.images, i, window.URL.createObjectURL(file))
130
130
 
131
131
  }
132
132
 

2

ソースの追記

2019/03/08 04:52

投稿

sauzar18
sauzar18

スコア163

test CHANGED
@@ -59,3 +59,81 @@
59
59
  }
60
60
 
61
61
  ```
62
+
63
+
64
+
65
+ 下記の感じですかねそしたら
66
+
67
+
68
+
69
+ ```html
70
+
71
+ <template>
72
+
73
+ <section class="sample">
74
+
75
+ <ul>
76
+
77
+ <li
78
+
79
+ v-for="(image, i) in images"
80
+
81
+ :key="i"
82
+
83
+ >
84
+
85
+ <input
86
+
87
+ type="file"
88
+
89
+ @change="onChange($event, i)"
90
+
91
+ >
92
+
93
+ <img :src="image">
94
+
95
+ </li>
96
+
97
+ </ul>
98
+
99
+ {{ images }}
100
+
101
+ </section>
102
+
103
+ </template>
104
+
105
+
106
+
107
+ <script>
108
+
109
+ export default {
110
+
111
+ name: 'sample',
112
+
113
+ data() {
114
+
115
+ return {
116
+
117
+ images: ["画像A", "画像B", "画像C"]
118
+
119
+ }
120
+
121
+ },
122
+
123
+ methods: {
124
+
125
+ onChange(e, i) {
126
+
127
+ let file = e.target.files[0]
128
+
129
+ this.$set(this.images, i, window.URL.createObjectURL(file))
130
+
131
+ }
132
+
133
+  }
134
+
135
+ }
136
+
137
+ </script>
138
+
139
+ ```

1

ソース修正

2019/03/08 04:49

投稿

sauzar18
sauzar18

スコア163

test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  <template>
6
6
 
7
- <section class="sample">
7
+ <section>
8
8
 
9
9
  <ul>
10
10
 
@@ -34,8 +34,6 @@
34
34
 
35
35
  export default {
36
36
 
37
- name: 'sample',
38
-
39
37
  data() {
40
38
 
41
39
  return {