我正在使用 Vue.js(版本 3)并且我想做这样的事情:
<div v-for="item in list" v-if="item.someAttribute === someOtherVariable">
但是 Vue 返回错误:
Property "item" was accessed during render but is not defined on instance
因为,正如我所想,他正在 data 中寻找 item,我在其中创建了 Vue 应用程序。 无论如何要解决这个问题?也许有一些变通方法可以获得相同的效果?
最佳答案
It's not recommended to use
v-if
andv-for
on the same element due to implicit precedence.
所以你应该这样做:
<template v-for="item in list">
<div v-if="item">
....
</div>
</template>
关于javascript - 我如何在 vue js 中使用内联声明的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73140124/