Skip to content
Advertisement

USe data from another object VueJs

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

Advertisement

Answer

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}`])
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement