Commit faad9f72 authored by lipengcheng 's avatar lipengcheng

vuex引入require.context

parent 7529dfc9
...@@ -14,9 +14,7 @@ export default { ...@@ -14,9 +14,7 @@ export default {
return this.$route.meta.layout || 'default-layout' return this.$route.meta.layout || 'default-layout'
} }
}, },
async created() { async created() {},
console.log('this.route:', this.route)
},
methods: { methods: {
async request() { async request() {
let result = await this.$http.get('/webapi/home/banner?type=1&category=18') let result = await this.$http.get('/webapi/home/banner?type=1&category=18')
......
...@@ -3,8 +3,7 @@ import layoutA from '@/components/layout/layoutA.vue' ...@@ -3,8 +3,7 @@ import layoutA from '@/components/layout/layoutA.vue'
// const install = Vue => { // const install = Vue => {
const requireComponent = require.context('.', true, /\.vue/) // const requireComponent = require.context('.', true, /\.vue/)
console.log('requireComponent:', requireComponent)
// requireComponent.keys().forEach(filename => { // requireComponent.keys().forEach(filename => {
// // 每个文件的详细信息 // // 每个文件的详细信息
// const config = requireComponent(filename) // const config = requireComponent(filename)
......
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import global from './global' const requireContext = require.context('.', true, /\.js$/)
import moduleA from './modules/moduleA' let modules = {}
import uploader from './modules/uploader' requireContext
.keys()
.filter((path) => path !== './index.js')
.forEach((path) => {
const moduleName = path.match(/.*(\/)(\S*).js/)[2]
if (moduleName === 'index') {
console.error('store/modules下的文件名不能为index')
return
}
const file = requireContext(path)
console.log('file:', file)
modules[moduleName] = file.default || file
})
Vue.use(Vuex) Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
...global, ...global,
modules: { modules
moduleA,
uploader
}
}) })
...@@ -37,7 +37,7 @@ module.exports = { ...@@ -37,7 +37,7 @@ module.exports = {
.loader('eslint-loader') .loader('eslint-loader')
.tap((options) => { .tap((options) => {
// 保存自动eslint修复 // 保存自动eslint修复
options.fix = false options.fix = true
return options return options
}) })
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment