解决TypeError: Right-hand side of 'instanceof' is not callable

问题

Vue项目中遇到这样的问题,没有提示具体哪个文件出问题,定位起来比较麻烦,后面发现是组件里props对象定义的类型有问题
TypeError: Right-hand side of 'instanceof' is not callable

在控制台里输入'jianhong' instanceof 'array'就会有这个错误

20200407234322120.png

解决

错误的写法(写快了 没注意到)

  props: {
    list: {
      type: {
        type: 'array',
        default: () => {
          return []
        }
      }
    }
  }

改写为正确的写法

  props: {
    list: {
      type: Array,
      default: () => {
        return []
      }
    }
  }

props里定义属性,type属性有以下7种(注意:首字母要大写)

  • String
  • Number
  • Function
  • Boolean
  • Object
  • Array
  • Symbol

props属性改正确之后,就解决了这个报错

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容