Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这就是我的组件模板的样子:
<tr v-for="row in user.data"> <td v-for="(value,key) in row"> {{key}}-{{value}} </td> </tr>
我想从这个循环中排除一些键,我知道最好的解决方案是使用计算函数,但不知道如何实现它。
您可以创建要忽略的键数组:
data: function () { return { ignore: [ 'key1', 'key2', 'key3' ]
然后添加 v-if 语句,该语句将遍历“ignore”数组并在键匹配时跳过输出:
<td v-for="(value,key) in row" v-if="!ignore.includes(row.key)"> {{key}}-{{value}} </td>