修改 src\views\home\Docker.vue
{{ item.title }}
主要是构建路由跳转。
增加代码如下:
......
......
const dockerList = [
{
active: true,
icon: 'custom-icon custom-icon-home',
title: '首页',
to: '/'
},
{
icon: 'custom-icon custom-icon-shopping',
title: '购物车',
to: '/cartList'
},
{
icon: 'custom-icon custom-icon-order',
title: '订单',
to: '/'
},
{
icon: 'custom-icon custom-icon-my',
title: '我的',
to: '/'
}
]
......
新增页面src\views\cartList\CartList.vue
cartList
新增路由:
src\router\index.js
{
path: '/cartList',
name: 'CartList',
component: () =>
import(
/* webpackChunkName: "cartList" */ '../views/cartList/CartList.vue'
)
},
新增订单页面
调整路由:
import { createRouter, createWebHistory } from 'vue-router'
const routes = [
......
{
path: '/orderConfirmation',
name: 'OrderConfirmation',
component: () =>
import(
/* webpackChunkName: "orderConfirmation" */ '../views/OrderConfirmation/OrderConfirmation.vue'
)
}
]
......
export default router
创建src\views\orderConfirmation\OrderConfirmation.vue
:
路由文件更新如下:
src\router\index.js
import { createRouter, createWebHistory } from 'vue-router'
const routes = [
{
path: '/',
name: 'Home',
component: () =>
import(/* webpackChunkName: "home" */ '../views/home/Home.vue')
},
{
path: '/login',
name: 'Login',
component: () =>
import(/* webpackChunkName: "login" */ '../views/login/Login.vue'),
beforeEnter: (to, from, next) => {
// 只有访问Login页面之前才会执行次函数
const { isLogin } = localStorage // 从本地存储中取isLogin
// 如果登录,就跳到首页页面;否则跳转到登录页面
isLogin ? next({ name: 'Home' }) : next()
}
},
{
path: '/register',
name: 'Register',
component: () =>
import(
/* webpackChunkName: "register" */ '../views/register/Register.vue'
),
beforeEnter: (to, from, next) => {
const { isLogin } = localStorage
isLogin ? next({ name: 'Home' }) : next()
}
},
{
path: '/shop/:id',
name: 'Shop',
component: () =>
import(/* webpackChunkName: "shop" */ '../views/shop/Shop.vue')
},
{
path: '/cartList',
name: 'CartList',
component: () =>
import(
/* webpackChunkName: "cartList" */ '../views/cartList/CartList.vue'
)
},
{
path: '/orderConfirmation',
name: 'OrderConfirmation',
component: () =>
import(
/* webpackChunkName: "orderConfirmation" */ '../views/orderConfirmation/OrderConfirmation.vue'
)
}
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
// beforeEach:全局,每次做路由跳转之前都会执行这个操作。
router.beforeEach((to, from, next) => {
// to and from are Route Object,
// to:跳转的时候想要跳转的页面的信息
// from :指从哪里跳过来的信息
// next() must be called to resolve the hook}
// 中间件继续执行的方法
// 从本地存储中取isLogin
const { isLogin } = localStorage
console.log(to, from)
/** 判断是否登录 */
// 必须双循环,才能防止死循环
// 如果没有登录,就跳到登录页面
const { name } = to
const isLoginOrRegister = name === 'Login' || name === 'Register'
isLogin || isLoginOrRegister ? next() : next({ name: 'Login' })
})
export default router
新建文件
src\views\orderConfirmation\OrderConfirmation.vue
orderConfirmation
修改src\views\shop\Cart.vue
......
去结算
......
跳转后需要知道是哪个商铺下的购物车订单。这时候需要带一个参数过去,可以修改如下:
src\views\orderConfirmation\OrderConfirmation.vue
......
去结算
......
修改路由:
src\router\index.js
{
path: '/orderConfirmation/:shopId',
name: 'OrderConfirmation',
component: () =>
import(
/* webpackChunkName: "orderConfirmation" */ '../views/orderConfirmation/OrderConfirmation.vue'
)
}
订单页面样式布局
首先完善一下骨架:
src\views\orderConfirmation\OrderConfirmation.vue
确认订单
收货地址
西安一二三大学四五六科技园2号楼
张三(先生)
18012341234
接下来增加样式:
这里背景超出长度会显示原来的蓝色。
优化如下:
增加样式:
进一步微调
确认订单
......
以上是模拟器的效果,考虑到真机浏览器的大小本来就会给上部留白,这里微调一下距上的距离:
&__header {
......
padding-top: 0.26rem;
......
&__back {
......
}
}
进一步,优化收货信息:
确认订单
收货地址
西安一二三大学四五六科技园2号楼
张三(先生)
18012341234
继续优化其他信息:
确认订单
收货地址
西安一二三大学四五六科技园2号楼
张三(先生)
18012341234
......