Skip to content

Commit

Permalink
Merge pull request #43 from School-of-Website-Engineering/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mason369 authored Jan 20, 2023
2 parents 6326fbf + f59b1b1 commit 3137b64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/request/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ export const reqGetUserInfo = () => request.get("/shop/userProfiles");

//商品详情
export const reqGetDetail = (id) => request.get(`/products/${id}`);

//加入购物车
export const reqAddCart = (params) => request.post("/shop/carts/add", qs.stringify( params ));
24 changes: 22 additions & 2 deletions src/views/Details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
</div>
</div>
<div class="btns">
<div class="addToCart">加入购物车</div>
<div class="addToCart" @click="addToCart">
加入购物车
</div>
<div class="buyNow">立即购买</div>
</div>
</div>
Expand Down Expand Up @@ -144,7 +146,7 @@

<script>
import Crumb from "@/components/Crumb";
import { reqGetDetail } from "@/request/api";
import { reqAddCart, reqGetDetail } from "@/request/api";
export default {
components: { Crumb },
// watch : {
Expand Down Expand Up @@ -216,6 +218,24 @@ export default {
return;
}
this.stepNum += val;
},
//加入购物车
async addToCart() {
const goodsId = this.$route.query.id;
const res = await reqAddCart({
productId: goodsId,
total : this.stepNum,
modified : 1
});
console.log(res);
//加入成功
if (res.code === 0) {
this.$message.success("加入购物车成功");
}
//加入失败
else {
this.$message.error(res.message);
}
}
}
};
Expand Down

0 comments on commit 3137b64

Please sign in to comment.