赞
踩
例如:
import request from '@/utils/request'
export default {
//请求收藏接口
getCollect(data) {
return request({
url: '/api/user/collect/getCollect',
method: 'post',
data: data
})
},
//删除收藏
deleteCollect(data) {
return request({
url: '/api/user/collect/deleteCollect',
method: 'post',
data: data
})
},
}
const routes = [
{
path: '/',
name: 'Home',
component: Home,
// *重定向
redirect: 'HomePage'
},
//* 首页
{
path: '/Shoppe',
name: 'Shoppe',
component: () => import(/* webpackChunkName: "首页" */ '../views/Shoppe.vue'),
children: [
{
path: '/HomePage',
name: 'HomePage',
component: () => import(/* webpackChunkName: "首页" */ '../views/HomePage.vue'),
},
{
path: '/goods',
name: 'goods',
component: () => import(/* webpackChunkName: "首页" */ '../views/Goods.vue'),
meta: {
break: ['全部商品', '分类'],
keepAlive: true,
}
},
{
path: '/details',
name: 'details',
component: () => import(/* webpackChunkName: "首页" */ '../components/module/Details.vue'),
},
{
path: '/myerror',
name: 'myerror',
component: () => import(/* webpackChunkName: "断网" */ '../components/module/myError.vue')
},
{
path: '/collect',
name: 'Collect',
component: () => import(/* webpackChunkName: "收藏" */ '../views/Collect.vue')
},
{
path: '/shopping',
name: 'shopping',
component: () => import(/* webpackChunkName: "购物车" */ '../views/Shopping.vue')
},
{
path: '/confirmOrder',
name: 'confirmOrder',
component: () => import(/* webpackChunkName: "订单" */ '../views/ConfirmOrder.vue')
},
{
path: '/Order',
name: 'Order',
component: () => import(/* webpackChunkName: "订单" */ '../views/Order.vue')
},
]
}
]
module.exports = {
publicPath: './',
//*再开开
devServer: {
open: true,
proxy: {
'/api':{
target: 'http://39.100.7.70:81/',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}
路由的鉴权,在没有登录的时候跳转购物车,我的收藏时 调用vuex中的方法,弹出登录框
//*路由鉴权
router.beforeEach((to, from, next) => {
//*判断有没有登录
if (store.state.token == "") {
//*去哪些页面
if (to.path == "/collect" || to.path == "/shopping") {
//*没有登陆就发送vuex
store.commit("uplogin")
}
}
next()
})
registerLogin: {
userName: [
{ validator: validateLogin1, required: true, trigger: "blur" },
{
pattern: /^[a-zA-Z]([-_a-zA-Z0-9]{5,16})$/,
message: "字母开头,长度5-16之间,允许字母数字下划线",
},
],
password: [{ validator: validateLogin2, trigger: "blur" }],
},
登录后如果购物车内总条数大于1时,购物车颜色高亮,
登录弹出框需要拆成组件,当没登陆时需要弹出
.elvesFigure {
width: 40px;
height: 40px;
background: url("../../assets/us-icon.png") no-repeat 0px 0px; /* 第一个图标*/
}
<el-menu
:default-active="activeIndex"
class="el-menu-demo"
mode="horizontal"
active-text-color="red"
router
>
<el-menu-item index="/">首页</el-menu-item>
<el-menu-item index="goods">全部商品</el-menu-item>
<el-menu-item index="3">关于我们</el-menu-item>
</el-menu>
determineSearch() {
this.$router.push({
path: `/goods?search=${this.search}`,
});
},
$route(val) {
if (val.query.categoryID) {
this.categoryID = val.query.categoryID;
this.getProductByCategory();
return;
}
if (val.query.search) {
this.search = val.query.search;
this.getProductBySearch();
}
},
<div class="slideshow">
<el-carousel height="460px">
<el-carousel-item v-for="(item, index) in carouselData" :key="index">
<img class="slideshowImg" :src="'api' + item.imgPath" alt="" />
</el-carousel-item>
</el-carousel>
</div>
//注册全局组件
import mymodel from './components/module/myModel'
Vue.component(mymodel.name, mymodel)
BrowseMore() {
let arr = [];
this.categoryName.forEach((item) => {
arr.push(item.category_id);
});
function data(arr) {
return [...new Set(arr)];
}
let list = data(arr);
this.$router.push({
path: "/goods?categoryID",
query: { categoryID: list },
});
},
<el-tabs v-model="activeName" type="card">
<el-tab-pane
v-for="item in tabList"
:key="item.category_id"
:label="item.category_name"
:name="'' + item.category_id"
></el-tab-pane>
</el-tabs>
<mymodel
style="lll"
:sTyle="{ width: '19%' }"
:categoryName="AllProduct"
:flags="false"
></mymodel>
<el-pagination
@current-change="currentChange"
:page-size="pageSize"
background
layout="prev, pager, next"
:total="total"
>
</el-pagination>
currentChange(currentPage) {
this.currentPage = currentPage;
},
//*加入购物车判断
async addShopping() {
if (this.$store.state.token == "") {
//*发送参数,显示弹框
this.$store.commit("uplogin");
} else {
//*请求数据
let { data: item } = await ShoppingApi.addShoppingCart({
user_id: this.$store.state.userId,
product_id: this.DetailsData.product_id,
});
this.$notify({
title: "成功",
message: item.msg,
type: "success",
});
}
},
//*添加收藏
async fond() {
if (this.$store.state.token == "") {
this.$store.commit("uplogin");
} else {
let { data: item } = await DetailsApi.addCollect({
user_id: this.$store.state.userId,
product_id: this.DetailsData.product_id,
});
// 添加收藏成功
if (item.code == "001") {
this.$notify({
title: "成功",
message: "添加收藏成功",
type: "success",
});
} else {
this.$notify.error({
title: "错误",
message: item.msg,
});
}
}
},
//*点击单选全选,发送数据到vuex,计算
handleSelectionChange(val) {
this.multipleSelection = val;
if (val.length > 0) {
this.flag = true;
} else {
this.flag = false;
}
this.$store.commit("handleSelectionChange", val);
},
// *删除
async deleteShoppingCart(data) {
let { data: item } = await shoppingApi.deleteShoppingCart({
user_id: this.$store.state.userId,
product_id: data.productID,
});
if (item.code == "001") {
// 删除购物车成功
this.$notify({
title: "成功",
message: item.msg,
type: "success",
});
this.getShoppingCart();
}
},
getters: {
//*总价格
totals(state) {
let amounts = 0
state.handleSelectionChange.forEach(item => {
amounts += item.price * item.num
})
return amounts
},
//*总个数
totalQuantity(state) {
let amounts = 0
state.handleSelectionChange.forEach(item => {
amounts += item.num
})
return amounts
},
},
<span>{{this.$store.getters.totalQuantity}}</span>
<mymodel
style="margin-top: 18px"
@collectList="collectList"
:CloseHide="true"
:sTyle="{ width: '19%' }"
:categoryName="collectionData"
:flags="false"
></mymodel>
async addOrder() {
let { data: item } = await comfirmorderApi.addOrder({
products: this.multipleSelection,
user_id: this.$store.state.userId,
});
if (item.code == "001") {
this.$notify({
title: "成功",
message: item.msg,
type: "success",
});
this.$router.push({
path: `/Order`,
});
}
},
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。