I’m working with Vue.js (version 3) and I wanted to do something like this:
JavaScript
x
2
1
<div v-for="item in list" v-if="item.someAttribute === someOtherVariable">
2
but Vue returns the error:
JavaScript
1
2
1
Property "item" was accessed during render but is not defined on instance
2
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?
Advertisement
Answer
It’s not recommended to use
v-if
andv-for
on the same element due to implicit precedence.
according to the official docs
so you should do :
JavaScript
1
6
1
<template v-for="item in list">
2
<div v-if="item">
3
.
4
</div>
5
</template>
6