How to use VueJS 2 global components inside single file components?(如何在单个文件组件中使用 VueJS 2 全局组件?)
问题描述
我正在尝试在单个文件组件中使用全局注册的组件(带有 Vue.component),但我总是得到
例如:
main.js:
home.vue:
如果我在本地注册它,它可以正常工作:
你不需要module.exports.你可以通过在 mycomponent.vue 文件中注册组件来全局注册.
然后添加到main.js中
或者我通常将它们注册到全局"文件中,然后将其导入主文件.
这应该允许您在应用程序的任何地方使用 my-component.
I am trying to use a globally registered component (with Vue.component) inside a single file component but I am always getting
For example:
main.js:
home.vue:
If I register it locally, it works OK:
You don't need the module.exports. You can register the component globally by having this within the mycomponent.vue file.
Then add to main.js
or I typically register them in a 'globals' file them import that into the main.
That should then allow you to use my-component anywhere in the app.
这篇关于如何在单个文件组件中使用 VueJS 2 全局组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!