如何使用 instanceof 运算符检查 props 数据中的参数类型?

how to use the instanceof operator to check parameter type in props data?

在 vue 指南文档中,我查看了有关 prop validation 的文档:

The type can be one of the following native constructors:

String

Number

Boolean

Function

Object

Array

In addition, type can also be a custom constructor function and the assertion will be made with an instanceof check.

那么,如何使用instanceof操作符实现参数自定义类型检查呢?

您可以使用自定义类型,例如:

props: {
  file: { type: File, required: true }
}