[英]Javascript and Vue.js infinite while loop in async function alternative
我目前使用異步 function 從 DOM 中插入一組特定元素,它目前工作得很好,但我無法通過 lint 驗證,所以我想知道是否有人知道更好的解決方案。 這是我當前的代碼:
async mounted() {
let colorMap = interpolate(['#fffbfb', '#ff4141']);
let i
// eslint-disable-next-line no-constant-condition
while (true) {
let switchColor = false
for (i = 0; i < 100; i++) {
let group = this.blinkingGroup
if (!switchColor) {
colorMap = interpolate(['#ff4141', '#fffbfb']);
} else {
colorMap = interpolate(['#fffbfb', '#ff4141']);
}
group.forEach(value => {
try {
value.dom.style.stroke = colorMap(i * 0.01)
} catch (e) {
//console.log(e)
}
})
await new Promise(r => setTimeout(r, 10));
switchColor = true
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.