加载时如何检查,如果product.thumbs数组(找到的第一个)有空元素,image === '' 则往里面插入数据,如果数组中没有空值,则只需推入数组
数组本身
product: {
thumbs: [
{
image: '',
thumb: '',
},
{
image: '',
thumb: '',
},
{
image: '',
thumb: '',
},
{
image: '',
thumb: '',
},
],
}
和下载功能
uploadGallery() {
const that = this
const galleries = event.target.files
galleries.forEach(function (value, index, product) {
const formData = new FormData()
formData.append('image', value)
formData.append('path', 'products')
that.$axios
.$post('/api/v1/shop/1/upload/image', formData, {
headers: { 'Content-Type': 'multipart/form-data' },
})
.then((response) => {
if (!that.product.image) {
that.product.image = response.path + response.image
}
that.product.thumbs.push({
image: response.image,
path: response.path,
})
})
.catch((error) => {
})
return index < that.countThumb + 1
})
},
像这样的东西
它可以通过一个函数来完成。因此,您不仅可以获得图像,还可以获得任何指定的密钥。