3
In a Javascript file, I have the following array group:
logo: [
require('@/assets/images/logos/lojas-' + cobrand[0] + '.png'),
require('@/assets/images/logos/lojas-' + cobrand[1] + '.png'),
require('@/assets/images/logos/lojas-' + cobrand[2] + '.png'),
require('@/assets/images/logos/lojas-' + cobrand[3] + '.png')
]
Each require
references an existing image in the folder logos
, where each image has the name of the store, as follows:
let cobrand = [
'informatica',
'mercearia',
'locadora',
'padaria'
]
So, inside the briefcase logo
I have an image for each cobrand
:
lojas-informatica.png
lojas-mercearia.png
lojas-locadora.png
lojas-padaria.png
Since it only has 4 items, it was very simple to use the form that is in this question, create an array with all the same changing only the index
of cobrand[i]
.
Only, when this gets bigger, it will become quite expensive. There is a way to do the array logo
have 1 line only with all cobrands
?
I thought I’d use the concat
as in this example I learned in another question:
[].concat(arrayum, arraydois, [ 'valueum', 'valuedois' ])
But this in a simple way will make all the cobrand
enter the URL together, which is not the case that I’m looking for.
I cannot create a Function unless it is within the array line logo: [].function aqui
or the for
as long as it is within this array as well
But it’s not just making one
for
in cobrand[] and us required put cobrand[i] ??– LeAndrade
@Leandrade can’t do a Function
– Roberto Monteiro
Hmmm, then complicates in man, having a Javascript file and not being able to create a function, is the same thing as going to Maresias and not like sand.
– LeAndrade
If I understand correctly what you want to do is something like
logo: cobrand.map(nome => require(\
@/Assets/images/logos/stores-${name}. png`))`. That’s it?– Andre
I will test here, apparently that’s right, it will create an array with all the options inside the cobrand, I will test and I tell you
– Roberto Monteiro
@exact user140828, on the console he created an array with all the images without running error, very good, this is very right
– Roberto Monteiro