关于VUE的v-if失效的一种可能

页面上v-if一直不起作用, 直到我打印结果时....

            let item=data.page.list[1]
            console.info(item.zstp && item.zstp.length>5)
            console.info(item.zstp && item.zstp.length>5)
            console.info(item.zstp && item.zstp.length>5)

打印的结果:

由于js的 逻辑运算符不返回逻辑值而导致的错误.

console.info(!!item.zstp && item.zstp.length>5)

这种强转就能正常返回逻辑值

posted @ 2021-06-19 17:50  风中的雪糕  阅读(2963)  评论(0编辑  收藏  举报