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

          {
            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)