我想将带有函数的路径传递给构造函数
this.elementImg.src = `${this.changeImage()}`;
为什么这不起作用
changeImage = () => {
if (this.speed < 6) {
this.imagePaths[0];
} else if (this.speed >= 6 && this.speed < 9) {
this.imagePaths[1];
} else if (this.speed >= 9) {
this.imagePaths[2];
}
}
答案 0 :(得分:1)
该函数需要return
条语句。
此外,您不需要进行>=
测试,因为先前的<
测试可确保该值将是该值的>=
或将不会用于{{1 }}。
else