main.js
import vue from 'vue'
import App from './App.vue'
import axios from 'axios'
axios.defaults.baseURL= 'HTTP://LOCALHOST:3000/api/'
Vue.prototype.$http = axios;
vue config.productionTip = false;
//子组件全局自动导入
const requireComponents = require.context("@/components",true,/\.vue/);
requireComponents.keys().forEach(filename=>{
// 组件实例
const reqCom = requireComponents(filename);
//获取路径作为组件名 (每个组件vue中要定义name)
const reqComName = reqCom.name || filename.replace(/\.\/(.*)\.vue/,"$1”)
console.log("filename:", reqComName,reqCom)
//挂载
Vue.component(reqComName,reqCom);
})
new Vue({
render:h=>h(App),
}).$mount("#app")