|
|
@@ -23,7 +23,12 @@ const files = ref([])
|
|
|
const fileInputRef = ref(null)
|
|
|
|
|
|
function onChange() {
|
|
|
- files.value = [...fileInputRef.value.files]
|
|
|
+ files.value.push([...fileInputRef.value.files][0])
|
|
|
+ let formData = new FormData();
|
|
|
+ formData.append('file', [...fileInputRef.value.files][0]);
|
|
|
+ uploadImage(formData).then(res => {
|
|
|
+ photoUrlList.value.push(res.result);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
function dragover(e) {
|
|
|
@@ -43,13 +48,6 @@ function drop(e) {
|
|
|
}
|
|
|
|
|
|
function generateURL(file) {
|
|
|
- let formData = new FormData();
|
|
|
- formData.append('file', file);
|
|
|
- uploadImage(formData).then(res => {
|
|
|
- photoUrlList.value.push(res.result);
|
|
|
- console.log(photoUrlList.value)
|
|
|
- });
|
|
|
-
|
|
|
let fileSrc = URL.createObjectURL(file);
|
|
|
setTimeout(() => {
|
|
|
URL.revokeObjectURL(fileSrc);
|
|
|
@@ -60,7 +58,7 @@ function generateURL(file) {
|
|
|
|
|
|
function remove(i) {
|
|
|
files.value.splice(i, 1);
|
|
|
- console.log(photoUrlList.value)
|
|
|
+ photoUrlList.value.pop();
|
|
|
}
|
|
|
|
|
|
const createDisabled = computed(() => {
|
|
|
@@ -75,6 +73,7 @@ function handleCreateProduct() {
|
|
|
price: price.value,
|
|
|
photoUrlList: photoUrlList.value
|
|
|
};
|
|
|
+ console.log(payload)
|
|
|
createProduct(payload).then(res => {
|
|
|
console.log(res);
|
|
|
})
|
|
|
@@ -156,10 +155,11 @@ function handleCreateProduct() {
|
|
|
<div v-else>将文件拖到此处或单击此处上传。</div>
|
|
|
</label>
|
|
|
|
|
|
+
|
|
|
<div class="preview-container mt-4" v-if="files.length">
|
|
|
<div v-for="file in files" :key="file.name" class="preview-card">
|
|
|
<div>
|
|
|
- <img class="preview-img" :src="generateURL(file)"/>
|
|
|
+ <el-image class="preview-img" :src="generateURL(file)" />
|
|
|
<p>
|
|
|
{{ file.name }}
|
|
|
</p>
|
|
|
@@ -191,8 +191,6 @@ function handleCreateProduct() {
|
|
|
</div>
|
|
|
</el-card>
|
|
|
</div>
|
|
|
-
|
|
|
-
|
|
|
</template>
|
|
|
|
|
|
<style scoped>
|