I have a jsonArray.js file
const jsonArray = [
{"click": "clearValue", "alt": "clearValueIcon",
"src" : "https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-edit-clear-icon.png",
"style": "grid-column:1/2;grid-row: 2/3;"},
{"click": "negativePositive", "alt": "negativePositiveIcon",
"src" : "https://image.flaticon.com/icons/svg/1777/1777560.svg",
"style":"grid-column:2/3;grid-row: 2/3"},
{"click": "percentage", "alt": "percentageIcon",
"src" : "https://image.flaticon.com/icons/svg/69/69839.svg",
"style":"grid-column:3/4;grid-row: 2/3;"}
]
In my App.vue file I import it and give the value to imagesData
beforeMount() {
this.imagesData = JsonArray;
}
Then I use a for loop to populate my img tags
<img
v-for="img in imagesData"
:key="img.alt"
@click="getFunction(img.click)"
:alt="img.alt"
:src="img.src"
:style="img.style"
/>
The only way I have been able to get the click to work is with a giant switch statement that evaluates the string and calls the method.
getFunction: function(fn) {
switch (fn) {
case "clearValue":
this.clearValue();
break;
case "negativePositive":
this.negativePositive();
break;
}}
I am thinking there is a better way, but cannot think of one.
clearValue()
andnegativePositive()
functions do? \$\endgroup\$JsonArray
!=jsonArray
! \$\endgroup\$