We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
建议不要在与v-for相同的元素上使用v-if。因为v-for指令的优先级高于v-if当它们处于同一节点。v-for 的优先级比 v-if 更高,这意味着 v-if 将分别重复运行于每个 v-for 循环中。
v-for
v-if
<ul> <li v-for="user in users" v-if="user.isActive" :key="user.id" > {{ user.name }} <li> </ul>
如果需要在列表中过滤掉不需要的某一项,建议使用计算属性。
computed: { activeUsers: function () { return this.users.filter(function (user) { return user.isActive }) } } ...... // ...... // <ul> <li v-for="user in activeUsers" :key="user.id"> {{ user.name }} <li> </ul>
将if指令添加到父级元素上,这可以避免对每个列表项进行条件判断。
if
<ul v-if="shouldShowUsers"> <li v-for="user in users" :key="user.id" > {{ user.name }} <li> </ul>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
建议不要在与
v-for
相同的元素上使用v-if
。因为v-for
指令的优先级高于v-if
当它们处于同一节点。v-for
的优先级比v-if
更高,这意味着v-if
将分别重复运行于每个v-for
循环中。如果需要在列表中过滤掉不需要的某一项,建议使用计算属性。
将
if
指令添加到父级元素上,这可以避免对每个列表项进行条件判断。The text was updated successfully, but these errors were encountered: