0

i have quick question here.

I have my object with value:

  data() {
    return {
      nation: {
        CZ: require("../../../../../svg/czech-flag.svg"),
      }
    };
  },

Then have API object (API is working fine, fyi)

  doctor: {
    region: "CZ"
  }

I wanna do something like this (is not working of course):

<div v-html="nation.doctor.region></div>

I had method for this, it worked, but I think it can be easier to do that. Thanks a lot for any help

2
  • 1
    Instead of all the ../../../ you can use @/ to get to the src/ directory. Your code will become much more clear. Commented Mar 9, 2021 at 7:31
  • Thank you for advice - in this project is still, i dont know why, not exist vue config file, so its not working yet. But I will use it, thank you! Commented Mar 9, 2021 at 8:38

1 Answer 1

1

You can use something like nations[`${doctor.region}`]

Working code:

const data = {
    nations: {
        CZ: 'Czech'
    }
}

const doctor = {
    region: 'CZ'
}

console.log(data.nations[`${doctor.region}`])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.