是否可以在 v-for 中使用 iterator?
methods: {
* makeRangeIterator(start = 0, end = Infinity, step = 1) {
let iterationCount = 0;
for (let i = start; i < end; i += step) {
iterationCount++;
yield i;
}
return iterationCount;
}
}
与
<div v-for="i in makeRangeIterator(1,10,2)">
<h1>{{i.value}}</h1>
</div>
没有输出
插值中有一个小错字。该行应为:
<div v-for="i in makeRangeIterator(1,10,2)">
<h1>{{i}}</h1>
</div>