如何检查对象是否是 Vue 组件? [英] How to check if an object is a Vue component?

查看:45
本文介绍了如何检查对象是否是 Vue 组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可靠的方法来检查对象是否是 Vue.js 组件?

Is there a reliable way to check if an object is a Vue.js component?

推荐答案

您可以使用 instanceof,如下代码:

You can use instanceof, as following code:

var isVueComp = vuecomp instanceof Vue

如果 isVueComp 为真,则它是 Vue.js 组件,否则不是.

If it isVueComp is true, it is a Vue.js componeny otherwise not.

您也可以使用 vuecomp.prototype.构造函数,它将返回对创建实例对象的对象构造函数的引用.

You can also use vuecomp.prototype.constructor, which will return reference to the Object constructor function that created the instance object.

检查这个fiddle.

这篇关于如何检查对象是否是 Vue 组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆