<template>
<div>
<h4>이미지 여러개 첨부</h4>
<el-table :data="items" size="mini" style="width: 100%;">
<el-table-column type="index" width="50" />
<el-table-column label="이미지">
<template #default="scope">
<el-input size="mini" type="text" v-model="scope.row.itemName" />
</template>
</el-table-column>
<el-table-column label="상품명">
<template #default="scope">
<el-input size="mini" type="text" v-model="scope.row.id" />
</template>
</el-table-column>
<el-table-column label="가격">
<template #default="scope">
<el-input size="mini" type="text" v-model="scope.row.id" />
</template>
</el-table-column>
<el-table-column label="판매수량">
<template #default="scope">
<el-input size="mini" type="text" v-model="scope.row.id" />
</template>
</el-table-column>
</el-table>
<table>
<thead>
<tr>
<th>번호</th>
<th>이미지</th>
<th>상품명</th>
<th>가격</th>
<th>판매수량</th>
</tr>
</thead>
<tbody>
<tr v-for="(tmp, idx) in count" :key="tmp">
<td>{{tmp}}</td>
<td>
<input type="file" ref="file" style="display:none;"
@change="handleImg($event, idx)" />
<img :src="imgsrc[idx]" @click="handleFile(idx)"
style="width:50px; cursor:pointer;" />
</td>
<td><input type="text" v-model="itemName[idx]" placeholder="상품명" /></td>
<td><input type="text" v-model="itemPrice[idx]" placeholder="가격" /></td>
<td><input type="text" v-model="itemQuentity[idx]" placeholder="수량" /></td>
</tr>
</tbody>
</table>
<input type="button" ref="btn1" class="button4" value="일괄등록" />
</div>
</template>
<script>
export default {
created() {
for(let i=0; i<this.count; i++){
this.imgsrc.push( require('../../assets/img/default.png') );
}
},
data() {
return {
count: 3,
imgsrc: [],
itemName: [],
itemPrice: [],
itemQuentity: [],
}
},
methods: {
handleImg(e, idx) {
console.log("Menu4.vue => handleImg", e, idx);
let self = this;
if(e.target.files[0]) {
const reader = new FileReader();
reader.addEventListener('load', function(e1) {
self.imgsrc[idx] = e1.target.result;
});
reader.readAsDataURL(e.target.files[0]);
}
},
handleFile(idx) {
console.log("Menu4.vue => handleFile", idx);
console.log(this.$refs.btn1);
console.log(this.$refs.file);
this.$refs.file[idx].click();
}
}
}
</script>
<style scoped>
</style>