Browse Source

master

master
邓宏 3 years ago
parent
commit
22a055136f
  1. 31
      src/store/index.js
  2. 16
      src/store/modules/data.js
  3. 2
      src/view/home.vue
  4. 1
      vite.config.js

31
src/store/index.js

@ -1,28 +1,15 @@
import { createStore } from 'vuex'
var moduleFile=import.meta.globEager("./modules/**/*.js")
const store = createStore({
state: {
userInfo: {
name:'myName'
}
},
mutations: {
getUserInfo (state, name) {
state.userInfo.name = name
}
},
actions: {
asyncGetUserInfo ({ commit }) {
setTimeout(() => {
commit("getUserInfo", +new Date() + 'action')
},2000)
}
},
getters: {
userInfoGetter (state) {
return state.userInfo.name
}
}
},
modules:Object.keys(moduleFile).reduce((a,b)=>{
a[b.match(/\/modules\/(.+)\.js/)[1]]=moduleFile[b].default
return a;
},{})
})
export default store

16
src/store/modules/data.js

@ -0,0 +1,16 @@
export default {
namespaced:true,
state:{
},
getters:{
},
mutations:{
},
actions:{
}
}

2
src/view/home.vue

@ -17,7 +17,7 @@
import HelloWorld from "@/components/HelloWorld.vue"
function img(){//
var img=import.meta.globEager('@/assets/img/logo.png')
var img=import.meta.globEager('@/assets/img/**/*.png')
return img['../assets/img/logo.png'].default
}
</script>

1
vite.config.js

@ -21,7 +21,6 @@ export default defineConfig({
rollupOptions:{
input:{ // 多项目打包
index: path.resolve(__dirname, 'index.html')
// index: path.resolve(__dirname, 'src/index.js')
},
// external:['vue'], // 控制插件不编译
output: {

Loading…
Cancel
Save