[Vuejs]-How to get value from this array in vuejs

0๐Ÿ‘

โœ…

You will need the value 691904 stored in some variable depending on some condition as 12 contains "12": [691904,649950,649031]. Then you can try:

computed: {
    selectedIndex() {
        const idx = votes.voteDict[catid].findIndex(num => num === 691904)
        return idx === -1 ? 0 : idx
    }
}

Then change your if statement to

<v-if="shop.poiId === votes.voteDict[catid][selectedIndex]">

Again, the number (691904) in the computed property should be a variable set according to some condition or dependent on the result of an API call.

0๐Ÿ‘

You should use Array.includes to test for the shop.poiId value. Also accessing "12" property of votes.voteDict would be like votes.voteDict[catId] where catId is the integer 12

<div v-if="votes.voteDict[catId].includes(shop.poiId)">

Leave a comment