Vue.js dynamically passing in functions I have a jsonArray.js file
const jsonArray = [
  {&quot;click&quot;: &quot;clearValue&quot;, &quot;alt&quot;: &quot;clearValueIcon&quot;, 
  &quot;src&quot; : &quot;https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-edit-clear-icon.png&quot;,
  &quot;style&quot;: &quot;grid-column:1/2;grid-row: 2/3;&quot;},
  {&quot;click&quot;: &quot;negativePositive&quot;, &quot;alt&quot;: &quot;negativePositiveIcon&quot;, 
  &quot;src&quot; : &quot;https://image.flaticon.com/icons/svg/1777/1777560.svg&quot;,
  &quot;style&quot;:&quot;grid-column:2/3;grid-row: 2/3&quot;},
  {&quot;click&quot;: &quot;percentage&quot;, &quot;alt&quot;: &quot;percentageIcon&quot;, 
  &quot;src&quot; : &quot;https://image.flaticon.com/icons/svg/69/69839.svg&quot;,
  &quot;style&quot;:&quot;grid-column:3/4;grid-row: 2/3;&quot;}
]

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
&lt;img
          v-for=&quot;img in imagesData&quot;
          :key=&quot;img.alt&quot;
          @click=&quot;getFunction(img.click)&quot;
          :alt=&quot;img.alt&quot;
          :src=&quot;img.src&quot;
          :style=&quot;img.style&quot;
        /&gt;

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 &quot;clearValue&quot;:
          this.clearValue();
          break;
        case &quot;negativePositive&quot;:
          this.negativePositive();
          break;
}}

I am thinking there is a better way, but cannot think of one.
First off, the file jsonArray.js doesn't contain &quot;JSON&quot;. It's a JavaScript source code file containing an JavaScript array literal which in turn contains JavaScript object literals. And since it's not JSON, you could theoretically put functions into the objects:
{
  alt: &quot;clearValueIcon&quot;, // Quotes around key are not needed, since it's not JSON
  src : &quot;...&quot;, // shortened
  style: &quot;grid-column:1/2;grid-row: 2/3;&quot;,
  handler() {
     this.value = &quot;&quot;; // For example
  }
}, 

And with a helping method:
methods: {
  callHandler(handler) {
     handler.call(this);
  }
}

&lt;img
     v-for=&quot;img in imagesData&quot;
     :key=&quot;img.alt&quot;
     @click=&quot;callHandler(img.handler)&quot;
     :alt=&quot;img.alt&quot;
     :src=&quot;img.src&quot;
     :style=&quot;img.style&quot;
/&gt;


However I don't really see the point of outsourcing the buttons into a data array like this. Unless you are using the array in some other way in the project, you should just straight up have a list of imgs (or custom &quot;button&quot; components) in your template.
Two more things:

The styles belong in the style sheet.
The chosen texts for the alt attributes are bad. They are supposed to be fallback texts that displayed to the user in the case the images can't be displayed to (or seen by) the user. For the shown buttons something like &quot;Clear&quot;, &quot;+/-&quot; and &quot;%&quot; would be better choices.

EDIT: One more thing: You shouldn't be using a plain image with a click handler, but for accessability wrap them in a &lt;button&gt; (or &lt;a&gt;) and put the handler on them.