Home > Back-end >  Value from a JSON file to change the background of element
Value from a JSON file to change the background of element

Time:01-11

I have a JSON file that I am calling with Axios to fetch data, in the data is a value. When this value is present, I want to change the background colour. Sounds simple enough but I am struggling with the logic of this.

Here is my code:

https://gcpzn.csb.app/

Here is some of my thinking on how to solve this:

In the test.json data above we get the data of type: "dev" there will be dev, stage, live from this JSON data, I need to be able to change the background colour based on these values I was thinking of using a switch statement but this is where I am stuck at.

If the item.type is dev then I want the background to change to yellow
If the item.type is stage then I want the background to change to red
If the item.type is live then I want the background to change to green

How would you go about solving this issue as I am stuck and need a little help, please?

Thanks,

Dave.

CodePudding user response:

You forget that calling an API is an asynchronous process. Here is your modified code.

  •  Tags:  
  • Related