3

I'm working with Vue.js (version 3) and I wanted to do something like this:

<div v-for="item in list" v-if="item.someAttribute === someOtherVariable">

but Vue returns the error:

Property "item" was accessed during render but is not defined on instance

Since, as I suppose, he's looking for item in data, where I created the Vue app. Is there anyway to solve this issue? Maybe some workaround to obtain the same effect?

1

2 Answers 2

1

It's not recommended to use v-if and v-for on the same element due to implicit precedence.

according to the official docs

so you should do :


<template v-for="item in list">
  <div v-if="item">
    ....
  </div>
</template>
Sign up to request clarification or add additional context in comments.

Comments

1

You can not access v-for and v-if in the same line, if you do so Priority has been given to your v-if condition , this was the reason you are getting that error

<div v-for="item in list">
  <span v-if="item.someAttribute === someOtherVariable">...</span>
</div>

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.