我不想推送 null,所以我设置了一个条件来检查,但有一个语法错误:
“‘void’类型的表达式无法测试其真实性”
我该如何正确地做到这一点?
localStorage.setItem('todoitems', JSON.stringify(this.todoitems))
? localStorage.setItem('todoitems', JSON.stringify(this.todoitems))
: [];
Since setItem https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem不返回任何内容,它抱怨使用void
输入需要布尔值的三元运算符
您可以添加一个if
条件为this.todoitems
before setItem
if (this.todoitems !== null)
localStorage.setItem('todoitems', JSON.stringify(this.todoitems))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)