demand

Element’s upload component has an attribute, and our requirement is to use this attribute to print out the original picture of the product to be edited, which may be N

:file-list="imgList"
Copy the code

The format I need is:

imgList:[
    {url:' 'xxx},
    {url:' 'xxx},
    {url:' 'xxx},
    {url:' 'xxx},
    ...
]
Copy the code

My data sent by the back end is:

imgList:'https://static.mdaren.cn/test2/photoUrl20210511134901.jpg,
https://static.mdaren.cn/test2/photoUrl20210511134904.jpg,
https://static.mdaren.cn/test2/photoUrl20210511134907.jpg'
Copy the code

To solve

What I need to do on my side:

// Set the data passed to me as data
const item= data.split(', ')//split(',') splits the string with a ','
for(i in item){
    console.log(i)// The printed I is key
    imgList.push({url:item[i]})//item[I] is the value we want
}
Copy the code

At this point, when the facade of the page, the original picture list can be displayed normally