如何管理不同文件夹结构中的相同名称组件。
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
/**
* The following block of code may be used to automatically register your
* Vue components. It will recursively scan this directory for the Vue
* components and automatically register them with their "basename".
*
* Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
*/
// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))
Vue.component('header', require('./components/Header.vue').default);
Vue.component('header', require('./components/site1/Header.vue').default);
Vue.component('header', require('./components/site2/Header.vue').default);
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
const app = new Vue({
el: '#app',
});
我正在laravel中开发hmvc结构。我正在对模块使用Caffeinated包。因此,所有模块的视图不同,所以我想在不同的文件夹中创建多个相同名称的componet文件。
我该如何管理?
Vue.component('header', require('./components/Header.vue').default);
Vue.component('header', require('./components/site1/Header.vue').default);
Vue.component('header', require('./components/site2/Header.vue').default);
您应该在导入期间为组件分配一个新名称,如下所示:
Vue.component('header-one', require('./components/Header.vue').default);
Vue.component('header-two', require('./components/site1/Header.vue').default);
Vue.component('header-three', require('./components/site2/Header.vue').default);
更好的是,为了提高应用程序的性能,您可以按如下所示延迟加载组件:
Vue.component('header-one', () => import('./components/Header.vue'));
Vue.component('header-two', () => import('./components/site1/Header.vue'));
Vue.component('header-three', () => import('./components/site2/Header.vue'));