Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mould-vuecli3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lhfe
mould-vuecli3
Commits
faad9f72
Commit
faad9f72
authored
Aug 30, 2020
by
lipengcheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vuex引入require.context
parent
7529dfc9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
13 deletions
+19
-13
App.vue
src/App.vue
+1
-3
index.js
src/components/layout/index.js
+1
-2
index.js
src/store/index.js
+16
-7
vue.config.js
vue.config.js
+1
-1
No files found.
src/App.vue
View file @
faad9f72
...
...
@@ -14,9 +14,7 @@ export default {
return
this
.
$route
.
meta
.
layout
||
'default-layout'
}
},
async
created
()
{
console
.
log
(
'this.route:'
,
this
.
route
)
},
async
created
()
{},
methods
:
{
async
request
()
{
let
result
=
await
this
.
$http
.
get
(
'/webapi/home/banner?type=1&category=18'
)
...
...
src/components/layout/index.js
View file @
faad9f72
...
...
@@ -3,8 +3,7 @@ import layoutA from '@/components/layout/layoutA.vue'
// const install = Vue => {
const
requireComponent
=
require
.
context
(
'.'
,
true
,
/
\.
vue/
)
console
.
log
(
'requireComponent:'
,
requireComponent
)
// const requireComponent = require.context('.', true, /\.vue/)
// requireComponent.keys().forEach(filename => {
// // 每个文件的详细信息
// const config = requireComponent(filename)
...
...
src/store/index.js
View file @
faad9f72
import
Vue
from
'vue'
import
Vuex
from
'vuex'
import
global
from
'./global'
import
moduleA
from
'./modules/moduleA'
import
uploader
from
'./modules/uploader'
const
requireContext
=
require
.
context
(
'.'
,
true
,
/
\.
js$/
)
let
modules
=
{}
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
)
export
default
new
Vuex
.
Store
({
...
global
,
modules
:
{
moduleA
,
uploader
}
modules
})
vue.config.js
View file @
faad9f72
...
...
@@ -37,7 +37,7 @@ module.exports = {
.
loader
(
'eslint-loader'
)
.
tap
((
options
)
=>
{
// 保存自动eslint修复
options
.
fix
=
fals
e
options
.
fix
=
tru
e
return
options
})
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment