Commit 150ec8e8 authored by bobo826's avatar bobo826

feat: 项目结构优化

parent 2b2bbe2a
<template>
<div class="hello">
this is helloworld components
</div>
</template>
<script>
export default {
name: 'HelloWorld',
props: {
msg: String,
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
import HelloWorld from './hello-world';
import GkHeader from './Header';
import GkHeader from './header';
export { HelloWorld, GkHeader };
export { GkHeader };
......@@ -2,8 +2,6 @@ import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '@/views/home';
const Cart = () => import('@/views/cart');
Vue.use(VueRouter);
// 单入口路由配置
......@@ -12,11 +10,6 @@ const routes = [
path: '/',
name: 'Home',
component: Home
},
{
path: '/cart',
name: 'Cart',
component: Cart
}
];
......
import Vue from 'vue';
import Vuex from 'vuex';
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);
Vue.use(Vuex)
const reqiureContext = require.context('./modules', false, /\.js$/);
const modules = {};
const reqiureContext = require.context('./modules', false, /\.js$/)
const modules = {}
reqiureContext.keys().forEach((key) => {
const name = key.slice(2, -3); // 得到 state的名称
const moduleConfig = reqiureContext(key).default || reqiureContext(key);
modules[name] = moduleConfig;
});
const name = key.slice(2, -3) // 得到 state的名称
console.log('reqiureContext(key).default', reqiureContext(key).default)
console.log('reqiureContext(key)', reqiureContext(key))
const moduleConfig = reqiureContext(key).default || reqiureContext(key)
modules[name] = moduleConfig
})
export default new Vuex.Store({
namespaced: true,
modules: {
...modules,
},
});
}
})
......@@ -2,21 +2,20 @@ const state = {
username: 'zhaoting',
address: '',
token: '',
};
}
const mutations = {
changeName(state, payload) {
state.username = payload;
},
};
}
const getters = {
currentUsername: (state) => state.username,
};
}
export default {
state,
getters,
mutations,
};
}
const state = {
carts: [],
};
const actions = {
addCart({ commit }, cart) {
setTimeout(() => {
commit('addCart', cart);
}, 1000);
},
deleteCart({ commit }, id) {
setTimeout(() => {
commit('deleteCart', id);
}, 1000);
},
deleteAll({ commit }) {
setTimeout(() => {
commit('deleteAll');
}, 1000);
},
};
const mutations = {
addCart(state, product) {
const { carts } = state;
carts.push(product);
state.carts = [...carts];
},
deleteCart(state, id) {
const carts = [...state.carts.filter((cart) => cart.id !== id)];
state.carts = carts;
},
deleteAll() {
state.carts = [];
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};
import * as storage from './storage'
export default {
storage
};
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
<template>
<div class='cartpage'>
<h1 v-for="item in carts" :key="item.id">
{{ JSON.stringify(item) }}
</h1>
<div>
<button @click="addCartInpage">add</button>
<button @click="deleteOne">deleteOne</button>
<button @click="deleteCartInpage">deleteAll</button>
</div>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
export default {
name: 'cart',
// import引入的组件需要注入到对象中才能使用
components: {
},
data() {
// 这里存放数据
return {
};
},
computed: {
...mapState({
carts: (state) => state.cart.carts,
}),
},
watch: {},
methods: {
...mapActions(['cart/addCart', 'cart/deleteAll', 'cart/deleteCart']),
addCartInpage() {
if (!this.addIndex) this.addIndex = 1;
this['cart/addCart']({ id: this.addIndex, cart: 'sfshfksfhs' });
this.addIndex += 1;
},
deleteCartInpage() {
if (!this.deleteIndex) {
this.deleteIndex = 1;
}
this['cart/deleteAll'](this.deleteIndex);
this.deleteIndex += 1;
},
deleteOne() {
}
},
created() {
},
mounted() {
},
};
</script>
<style lang='scss' scoped>
</style>
......@@ -17,14 +17,7 @@ export default {
name: 'Home',
components: {
},
methods: {
// show() {
// this.$message({
// type: 'info',
// message: 'this is message',
// });
// },
},
methods: {},
};
</script>
......
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