简体   繁体   English

使用vuejs显示多个图像

[英]Display several images with vuejs

I am new to Vue and i wonder if there is a way to upload and display several images at once 我是Vue的新手,我想知道是否可以同时上传和显示多个图像

<input type="file" name="photo" accept="image/*" @change="onFileChange($event.target.files)" />
<div id="preview">
    <img v-if="url" :src="url" />data() {
    return {
        url: [],
    }
},
methods: {
    onFileChange(event) {
        const files = event.target.files;

        for(let i = 0; i < files.length; i++) {

            const file = files[i];
            this.url = URL.createObjectURL(file);
        }

    }
}

我认为您正在寻找向input标签添加multiple属性的方法:

<input type="file" multiple name="photo" accept="image/*" @change="onFileChange($event.target.files)" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM