gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:59:02 31 4
gpt4 key购买 nike

我有一个名为 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. .

最佳答案

没有公共(public) API 可以执行此操作。

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

否则你可以这样取消注册:

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

关于javascript - 如何在 Vue 中完全删除全局组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58704842/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com