美文网首页
字符串'true'/'false'转Boolean

字符串'true'/'false'转Boolean

作者: big_fang | 来源:发表于2019-01-15 17:24 被阅读0次
          {
            name: 'XXX',
            path: 'repeat-customer-query', 
            hideInMenu: localStorage.getItem('show_customers'),
          },

如上代码,在antdesign框架使用中,菜单栏某一项需要通过hideInMenu来设定显示还是隐藏,由于hideInMenu只接受Boolean值的true或false,所以直接localStorage.getItem获得的值不行,因为localStorage.getItem获得值类型是string,所以使用必须如下方式:

          {
            name: 'XXX',
            path: 'repeat-customer-query', 
            hideInMenu: localStorage.getItem('show_customers') === 'true',
          },

参考来源:JS字符串False转Boolean

相关文章

网友评论

      本文标题:字符串'true'/'false'转Boolean

      本文链接:https://www.haomeiwen.com/subject/wgwydqtx.html