上传多张图片路径问题、用轮播图展示已上传的多张图片

不知道数组之中有几个值,如this.fileList=[hdehdueh,dehbebfhb,fhruhfurh],现需求将数组中的每一项放入const img=""之中,每一个值用逗号隔开

const fileList = ['hdehdueh', 'dehbebfhb', 'fhruhfurh'];
const img = fileList.join(',');
console.log(img);
//const img ="hdehdueh,dehbebfhb,fhruhfurh"

不知道数组之中有几个值,如this.fileList=[{url:hdehdueh},{url:dehbebfhb},]{url:dehbebfhb},现需求将数组中的每一项的url值放入const img=""之中,每一个值用逗号隔开

const fileList = [{url: 'hdehdueh'}, {url: 'dehbebfhb'}, {url: 'fhruhfurh'}];
const img = fileList.map(item => item.url).join(',');
console.log(img);
//img变量的值就会是"hdehdueh,dehbebfhb,fhruhfurh",其中每一个url值用逗号隔开了。

 现在倒回去,const img="hdehdueh,dehbebfhb,fhruhfurh",以逗号分隔,转变成this.fileList=[{url:hdehdueh},{url:dehbebfhb},]{url:dehbebfhb}]

const img = 'hdehdueh,dehbebfhb,fhruhfurh';
const fileList = img.split(',').map(item => ({url: item}));
console.log(fileList);
//这样就会得到一个包含三个对象的数组,其中每个对象都有一个url属性,对应着原来的字符串数组中的每个值

你可能感兴趣的:(前端,javascript,html)