Vue-cli cannot use slot to achieve content distribution after dynamically registering components with webpack

  • content distribution cannot be implemented using slot after dynamically registering components with webpack
  • there is no problem with a separate registration component. I don"t know what the problem is
  • the following is the webpack dynamic registration component code
import Vue from "vue";

function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

const requireComponent = require.context(
    ".",
    true,
    /\.vue$/
);

requireComponent.keys().forEach(fileName => {
    console.log(`${fileName.substring(fileName.lastIndexOf("/")  + 1).replace(/\.\w+$/, "")}      :"${fileName}"`);
    const componentConfig = requireComponent(fileName);
    const componentName = capitalizeFirstLetter(
        fileName.substring(fileName.lastIndexOf("/")  + 1).replace(/\.\w+$/, "")
    );
    Vue.component(componentName, componentConfig.default || componentConfig);
});
Mar.23,2021

resolved, non-webpack problem

Menu