<script> const path = require('path') const files = require.context('@/pages/home/components', false, /.vue$/) //这句话的意思是引入components下的所有vue文件,@需要在vue.config.js配置alias const modules = {} files.keys().forEach(key => { const name = path.basename(key, '.vue') modules[name] = files(key).default || files(key) }) export default{ components:{ ...modules } } </script>