Answer the question
In order to leave comments, you need to log in
How to globally register components, in a loop?
According to the article , the solution is not suitable, because. all components are scattered throughout the structure in different folders and modules. For this, a separate file has been created in each module, which lists all the necessary components for global registration.
The idea was this:
When building, the application bypasses the folders of the module, which contains the file with the global components of the module, in the form of an object (key -> name, value - location). Then I include a file with this object and iterate over its properties, registering the component.
// Пример структуры файла одного из модулей
export default {
ModulePageItemsTypes: "./components/pages/items/ModulePageItemsTypes",
.....
}
import globalComponents from './pathToModule/globals'
for (var key in globalComponents) {
// Вот так компонент регистрируется (если указывать путь строкой)
Vue.component(key, require('./components/pages/items/ModulePageItemsTypes').default);
// Если путь указан через переменную цикла, то при сборке выдает ошибку.
Vue.component(key, require(globalComponents[key]).default);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question