如何在Vue中完全删除全局组件



我有一个名为button-widget的组件,它是全局注册的。

Vue.component('button-widget', {
template: `<button>My Button</button>`
})

现在,如何永久删除此组件?

我不是在谈论v-if$destroy()——我只想以从未定义过的方式完全删除此组件,因此,例如,我收到了以下警告:Unknown custom element: <button-widget> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

没有公共的API可以做到这一点。

正确的解决方案不是首先全局注册它,而是通过将它添加到要在其中使用的每个组件的components选项中,在每个组件的基础上使用它

否则,您可以这样注销:

delete Vue.options.components['button-widget']

最新更新