Skip to content

Commit

Permalink
feat:更新Vuex状态管理
Browse files Browse the repository at this point in the history
  • Loading branch information
mason369 committed Jan 13, 2023
1 parent e245ac8 commit 7845b39
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 49 deletions.
19 changes: 16 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
<Header></Header>
<!-- 路由出口 -->
<router-view></router-view>
<Home></Home>
<Footer></Footer>

<!-- 登录 -->
<Login v-show="isShowLoginModal"></Login>
</div>
</template>

Expand All @@ -15,16 +17,27 @@
import Header from "./components/Header";
import Footer from "./components/Footer";
import TopBar from "./components/TopBar";
import Home from "./views/Home";
import Login from "./components/Login";
import { mapState } from "vuex";
export default {
data() {
return {};
},
name : "App",
//注册组件
components: {
TopBar,
Header,
Footer,
Home
Login
},
// 计算属性
computed: {
...mapState({
isShowLoginModal: (state) =>
state.isShowLoginModal.isShowLoginModal
})
}
};
</script>
Expand Down
25 changes: 20 additions & 5 deletions src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
<!-- 导航与搜索 -->
<div class="nav">
<ul>
<li class="active">
<li
@click="$router.push('/home')"
:class="$route.path === '/home' ? 'active' : ''"
>
首页
</li>
<li>
<li
@click="$router.push('/goods')"
:class="$route.path === '/goods' ? 'active' : ''"
>
全部商品
</li>
<li>
<li
@click="$router.push('/user')"
:class="$route.path === '/user' ? 'active' : ''"
>
个人中心
</li>
<li>
<li
@click="$router.push('/order')"
:class="$route.path === '/order' ? 'active' : ''"
>
我的订单
</li>
<li>
<li
@click="$router.push('/free')"
:class="$route.path === '/free' ? 'active' : ''"
>
专属福利
</li>
</ul>
Expand Down
44 changes: 44 additions & 0 deletions src/components/Login.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<div class="login-modal">
<div class="mask" @click="this.close"></div>
<div class="login-box"></div>
</div>
</template>

<script>
import { mapMutations } from "vuex";
export default {
methods: {
...mapMutations({setIsShowLoginModal: "isShowLoginModal/setIsShowLoginModal"}),
close() {
this.setIsShowLoginModal(false);
}
}
};
</script>

<style lang="scss" scoped>
.login-modal {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
.mask {
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
}
.login-box {
width: 555px;
height: 423px;
background-image: url(../assets/img/login-box-bg.png);
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
}
</style>
14 changes: 12 additions & 2 deletions src/components/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@
<li>我的鸡腿:--</li>
<li>获取鸡腿</li>
<li>叩丁狼官网</li>
<li class="btn">登录</li>
<li class="btn" @click="login">登录</li>
</ul>
</div>
</div>
</nav>
</template>

<script>
export default { name: "TopBar" };
import { mapMutations } from "vuex";
export default {
name : "TopBar",
methods: {
...mapMutations({setIsShowLoginModal: "isShowLoginModal/setIsShowLoginModal"}),
login() {
// 触发登录弹窗
this.setIsShowLoginModal(true);
}
}
};
</script>

<style scoped lang="scss">
Expand Down
4 changes: 1 addition & 3 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ VueRouter.prototype.replace = function(location, resolve, reject) {
};


let router = new VueRouter({
export default new VueRouter({
routes,
scrollBehavior() {
return { y: 0 };
Expand All @@ -48,5 +48,3 @@ let router = new VueRouter({
mode: "history"
});


export default router;
61 changes: 35 additions & 26 deletions src/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,40 @@ export default [
//重定向
{
path : "/",
redirect: ""
redirect: "Home"
},
//首页组件
{
path : "/home",
component: () =>
import(/* webpackChunkName: "home" */ "@/views/Home"),
name: "home"
},
//全部商品组件
{
path : "/goods",
component: () =>
import(/* webpackChunkName: "goods" */ "@/views/Goods"),
name: "goods"
},
//个人中心组件
{
path : "/user",
component: () => import(/* webpackChunkName: "user" */ "@/views/User"),
name : "user"
},
//订单组件
{
path : "/order",
component: () =>
import(/* webpackChunkName: "order" */ "@/views/Order"),
name: "order"
},
//free
{
path : "/free",
component: () =>
import(/* webpackChunkName: "free" */ "@/views/Free"),
name: "free"
}
// //导入登录组件
// {
// path : "/login",
// component: () =>
// import(/* webpackChunkName: "login_home_welcome" */ "@/components/Login"),
// name: "login"
// },
// //导入主页组件
// {
// path : "/home",
// component: () =>
// import(/* webpackChunkName: "login_home_welcome" */ "@/components/Home.vue"),
// name : "home",
// redirect: "/welcome",
// children: [
// {
// //导入欢迎组件
// path : "/welcome",
// component: () =>
// import(
// /* webpackChunkName: "login_home_welcome" */ "@/components/Welcome"
// ),
// name: "welcome"
// },
// }
];
15 changes: 5 additions & 10 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import Vue from "vue"
import Vuex from "vuex"
import Vue from "vue";
import Vuex from "vuex";
import isShowLoginModal from "@/store/isShowLoginModal";

Vue.use(Vuex)
Vue.use(Vuex);

export default new Vuex.Store({
state : {},
getters : {},
mutations: {},
actions : {},
modules : {}
})
export default new Vuex.Store({modules: {isShowLoginModal}});
10 changes: 10 additions & 0 deletions src/store/isShowLoginModal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
namespaced: true,
actions : {},
mutations : {
setIsShowLoginModal(state, isShowLoginModal) {
state.isShowLoginModal = isShowLoginModal;
}
},
state: { isShowLoginModal: false }
};
18 changes: 18 additions & 0 deletions src/views/Free.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<div>
asdfasedfd
</div>
</template>

<script>
export default {
name: "User",
data() {
return {};
}
}
</script>

<style lang="scss" scoped>
</style>
13 changes: 13 additions & 0 deletions src/views/Goods.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>

</div>
</template>

<script>
export default {}
</script>

<style lang="scss" scoped>
</style>
13 changes: 13 additions & 0 deletions src/views/Order.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>

</div>
</template>

<script>
export default {}
</script>

<style lang="scss" scoped>
</style>
13 changes: 13 additions & 0 deletions src/views/User.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>

</div>
</template>

<script>
export default {}
</script>

<style lang="scss" scoped>
</style>

0 comments on commit 7845b39

Please sign in to comment.