Vue报错:Unnecessary use of boolean literals in conditional expression
在写网页的吸顶效果时,出现错误:Unnecessary use of boolean literals in conditional expressiondata(){return {isFixed: false}},mounted(){window.addEventListener('scroll', this.initHeight)},destroyed(){window.removeEven
·
在写网页的吸顶效果时,出现错误:Unnecessary use of boolean literals in conditional expression
data(){
return {
isFixed: false
}
},
mounted(){
window.addEventListener('scroll', this.initHeight)
},
destroyed(){
window.removeEventListener('scroll', this.initHeight)
},
methods: {
initHeight(){
var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
this.isFixed = scrollTop > 152 ? true : false; //错误在这一行
}
}
原因是Eslint的检查,说是如果有更简单的方案时,不允许使用三元运算符:
把错误行改成以下代码即可:
this.isFixed = scrollTop > 152;
更多推荐
已为社区贡献2条内容
所有评论(0)